【发布时间】:2011-06-16 12:43:26
【问题描述】:
我正在加载 UITableView,有时它会有 5 个单元格,有时会有 4 个单元格。根据它将有多少个单元格,我想为第 2 行或第 3 行设置 AccessoryDetail 按钮。我知道该条件有效,因为我已使用didSelectRowAtIndexPath: 成功尝试过,但由于某种原因,TableView 似乎没有根据显示的行数进行更新。我在viewWillAppear: 和[tableView reloadData] 中成功地重新加载了TableView 数据,但这并不能解决我的AccessoryDetail 问题。我试过使用[tableView reloadInputViews]无济于事。问题是 AccessoryDetail 图像始终设置为第 2 行或第 3 行,具体取决于我开始从应用程序加载哪个视图。
这是cellForRowAtIndexPath: 方法的逻辑:
if ((row == 2) && ([[self.office boxAddress] length] == 0) || (row == 3) && ([[self.office boxAddress] length] != 0)) {
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
编辑: 我已经根据 Simon Lee 的建议用 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 方法或发布屏幕截图。
标签: objective-c ios cocoa-touch uitableview reloaddata