0

UITableViewCell長い努力の末、必要なテーブル形式を思いついたので、静的デザインを採用する正当な理由があります。ストーリーボードですべてのtableView行を設計しました。

さて、1行だけ-その行にチェックマークを付ける-私は方法を見つけていません。プログラムロジックに基づいてそれを行う必要があります。

データソース メソッドを実装する場合cellForRowAtIndexPath、他のすべてのセルに対しても何かを行う必要があります。そして、それをしている間、他のセルに対して静的に行ったすべての書式設定を消去します。他のすべてのセルに戻るnilと、それらは表示されません。

私は、このコードでこの特定のセルを選び出そうとしましたUITableViewControllerviewdidLoad:

NSIndexPath* NotifyRow = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:NotifyRow];

if (MYCONDITION_IS_TRUE)
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
    cell.accessoryType = UITableViewCellAccessoryNone;

しかし、私は常に取得するため、上記は機能しませんcell=nil。仕組みが組み込まれているため、絵コンテに表のデザインがある場合、それをself.tableView構造的に共有することはありません。最初のステートメントで行とセクションの値を変更しようとしましたが、すべてのセルがnil.

静的設計から、変更したいこの 1 つのセルをどのように選び出すのですか?

4

1 に答える 1

0

Soon after posting, I realized my mistake. I was calling cellForRowAtIndexPath too early to get the cell - even before the view was fully laid.

Just added one row on top of everything in my viewDidLoad, and it worked:

[self.tableView reloadData];

So the whole will look like:

[self.tableView reloadData];
NSIndexPath* NotifyRow = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:NotifyRow];

if (MYCONDITION_IS_TRUE)
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
    cell.accessoryType = UITableViewCellAccessoryNone;
于 2012-11-07T19:54:21.980 に答える