すべてではない、いくつかのセルにUITableViewCellのアクセサリーの種類を設定します

StackOverflow https://stackoverflow.com/questions/2541669

質問

私は自分のUITableViewControllerで構築されている8個の細胞を持っています。私は4日と8細胞上の開示インジケーターを表示することができますどのように知っていただきたいと思います。今、私はそれを構築しています。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

私はすべてのセルに開示インジケーターを追加しようとしている完全に承知しているものの、

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
役に立ちましたか?

解決

if文シンプルを使用します:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ... // do whatever
    UITableViewCellAccessoryType accessoryType = UITableViewCellAccessoryNone;
    if (indexPath.row == 3 || indexPath.row == 7) {
        accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.accessoryType = accessoryType;
    ... // do whatever
}

他のヒント

あなたはindexPathはなぜだけでなく、条件付きで開示指標を適用する、知っているとき

if((indexPath.row == 3) || (indexPath.row == 7))

(indexPath.rowはもちろん0ベースのさ...第四は3であり、第八は7です。そして、あなたはあまりにもそこから出マジックナンバーを保つための#defineまたはいくつかの他の方法を使用する必要があります。)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top