1

カスタムセルでテーブルを作成しました。すべてのセルはテキストフィールドです。次の画像リンクに示すように、ランダムセルをクリックすると、他のフォーカスされていないセルにシャドウレイヤー(透明なボックグラウンド)が表示されるようにしたいと思います。

http://i47.tinypic.com/nwd45e.png

4

1 に答える 1

1

ストーリーボード/xibでtableViewCellの背景をデフォルトの色(tableViewの色を希望どおりにするために基本的にクリア)に設定している場合は、次のように実行できます。

// assume that the background color for the tableView in the storyboard is lightOrange,
// as seen in http://i47.tinypic.com/nwd45e.png

- (UITableViewCell*)tableView:(UITableView*)tableView
        cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    ... the normal code for getting your cell, probably involving DequeueReusableCell ...

    // yes, the following gets called for every row even when selection doesn't change,
    // but it is a very small hit.  could be replaced by overriding reloadData for the
    // tableView, but that isn't always desirable.
    if (tableView.indexPathForSelectedRow)
        tableView.backgroundColor = [UIColor grayColor];
    else
        tableView.backgroundColor = [UIColor lightOrangeColor];

    return cell;
}

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    ... whatever else you would do for a selected row, perhaps a segue or something ...
    ... (and if part of this is to de-select a row that is already selected, take that ...
    ... into account as a conditional for the following line of code.

    tableView.backgroundColor = [UIColor grayColor];
}
于 2012-06-30T22:09:00.143 に答える