2013-07-22 57 views
-2

我寫過一個程序,它將一組對象存儲在一個標籤下,並且可以稍後查看和更改標籤。我已經寫了下面的代碼(僅包括添加複選標記的部分):複選標記未出現在UITableView中

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

cell.selectionStyle = UITableViewCellSelectionStyleNone; //To avoid the blue selection 
//necessary codes to populate the table here 
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; 
return cell; 
} 

但是表格甚至沒有顯示任何複選標記。是的,我通過評論cell.selectionStyle = UITableViewCellSelectionStyleNone;再次嘗試,仍然沒有用。我沒有在其他地方編寫任何代碼來取消選中已選中的複選標記。

+2

嘗試cell.accessoryType = UITableViewCellAccessoryCheckmark; – Girish

+0

你在那裏有無限的遞歸。 – Fogmeister

+0

無限遞歸?怎麼樣? –

回答

3

你爲什麼要設置附件類型這樣 [tableView cellForRowAtIndexPath:indexPath].accessoryType,因爲你所得到的細胞本身在這個方法中

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; //To avoid the blue selection 
     //necessary codes to populate the table here 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; //Do like this 
     return cell; 
} 


1

更換

[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; 

cell.accessoryType = UITableViewCellAccessoryCheckmark; 
1

要對號出現使用

cell.accessoryType = UITableViewCellAccessoryCheckmark; 
相關問題