我正在加載一個UITableView有時它會有5個單元格,有時4個單元格。根據有多少個單元格,我想爲第2行或第3行設置AccessoryDetail按鈕。我知道這個條件起作用,因爲我已經用didSelectRowAtIndexPath:
成功地嘗試了它,但由於某種原因,TableView似乎沒有得到根據顯示的行數來更新。我正在使用[tableView reloadData]
成功地在viewWillAppear:
中重新加載TableView數據,但是這對我來說並沒有照顧到AccessoryDetail問題。我試過使用[tableView reloadInputViews]
無濟於事。問題是AccessoryDetail圖像總是設置爲第2行或第3行,這取決於我從應用程序開始加載哪個視圖。iOS的AccessoryDetail圖像不重新更新時UITableView
下面是來自cellForRowAtIndexPath:
方法的邏輯:
if ((row == 2) && ([[self.office boxAddress] length] == 0) || (row == 3) && ([[self.office boxAddress] length] != 0)) {
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
編輯: 我已經改變了西門依李的帶有else子句的建議,我的方法是這樣的,但它似乎沒有任何工作:
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:OfficeCellIdentifier] autorelease];
if ((row == 2) && ([[self.office boxAddress] length] == 0) || (row == 3) && ([[self.office boxAddress] length] != 0)) {
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
//NSLog(@"row == 2 && [[self.office boxAddress] length] == 0 || row == 3");
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
@請詳細說明您的問題。通過發佈您的cellForRowAtIndexPath方法或發佈屏幕截圖。 – 2011-06-16 12:45:43