2010-01-19 32 views
0

我想要我的表視圖上的所有行使用UITableViewCellAccessoryNone(例如右邊沒有按鈕),除非他們被選中,在這一點上,我想使用UITableViewCellAccessoryDe​​tailDisclosureButton。例如。只有一行(如果沒有選擇,則沒有)每次都有按鈕。UITableView:如何使UITableViewCellAccessoryDe​​tailDisclosureButton出現在選區上?

這可能嗎?執行accessoryTypeForRowWithIndexPath的通常做法似乎不能動態工作 - 例如無論選擇什麼,它只會被調用一次。

感謝

回答

1

如果更改單元格的內容,你要打電話-reloadRowsAtIndexPaths:withRowAnimation:在你的tableview。

+0

謝謝Ben!這很好。 – 2010-01-19 18:41:12

3

注意別人嘗試這個..的accessoryTypeForRowWithIndexPath委託方法現在已經大幅貶值,如果你嘗試它,你會得到這樣的信息:

警告:由於使用傳統的單元佈局 委託執行 的tableView的:accessoryTypeForRowWithIndexPath: in。請 刪除您執行此 方法並將單元格屬性 accessoryType和/或 editingAccessoryType移至 新單元格佈局行爲。在將來的 版本中將不再調用此方法 。

相反,在你的UITableViewCell子類中實現setSelected方法。如上所述withRowAnimation方法:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 

[super setSelected:selected animated:animated]; 

// Configure the view for the selected state 

if (selected) { 
    self.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
} else { 
    self.accessoryType = UITableViewCellAccessoryNone; 
} 

..then使用reloadRowsAtIndexPaths。

相關問題