我在使用iOS 5新功能选择多个单元格时遇到了问题。 应用程序结构如下:
-> UIViewController
---> UITableView
----> CustomUITableViewCell
在这里,UIViewController
既是 UITableView
的委托对象,也是数据源(由于某些要求,我无法使用 UITableViewController
,所以采用了 UIViewController
)。单元格通过以下代码加载到 UITableView
中。
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell = (CustomTableViewCell*)[tv dequeueReusableCellWithIdentifier:kCellTableIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCellXib" owner:self options:nil];
cell = self.customTableViewCellOutlet;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// configure the cell with data
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
单元格界面已从xib文件创建。特别是,我创建了一个新的xib文件,其中父视图由UITableViewCell
元素组成。为了提供自定义,我将该元素的类型设置为CustomUITableViewCell
,其中CustomUITableViewCell
扩展了UITableViewCell
。
@interface CustomTableViewCell : UITableViewCell
// do stuff here
@end
代码运行良好。表格中显示了自定义单元格。现在,在应用程序执行期间,我将
allowsMultipleSelectionDuringEditing
设置为YES
,并进入UITableView
的编辑模式。它似乎有效。实际上,每个单元格旁边都会出现一个空圆圈。问题是当我选择一行时,空圆圈不改变其状态。理论上,这个圆圈必须从空白变成红色的勾号,反之亦然。看来圆圈仍然停留在单元格的contentView
上方。我已经进行了很多实验。我也检查了下面的方法。
- (NSArray *)indexPathsForSelectedRows
在编辑模式下进行选择时,它会得到更新。它显示正确的选定单元格。
对我来说不太清楚的是,当我尝试使用UITableViewCell
而不是自定义单元格时,圆圈会正确地更新其状态。
您有任何建议吗?提前感谢您。