【发布时间】:2012-02-24 11:40:39
【问题描述】:
我在使用 iOS 5 新功能在编辑模式下选择多个单元格时遇到问题。 应用结构如下:
-> UIViewController
---> UITableView
----> CustomUITableViewCell
其中UIViewController 既是UITableView 的代表又是数据源(出于需求原因,我使用UIViewController 而不是UITableViewController,我无法更改它)。单元格被加载到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,圆圈会正确更新其状态。
你有什么建议吗?提前谢谢你。
【问题讨论】:
标签: ios uitableview ios5 multipleselection