自定义editingAccessoryView行为不可预知

好的,首先,我希望我的单元格在编辑模式下(使用一些更好的button)查看我的UItableView:

在这里输入图像说明

但是 – 这是现在的样子:

在这里输入图像说明

我的问题是我的自定义EditingAccessoryView只出现在我第一次创build的单元格上,并且出现了那些circle-thingies(那些叫什么?)。 哪个不太好。

现在,我的代码看起来像这样(这似乎是这样做的常见方式,看到这个问题,例如: 如何添加自定义EditingAccessoryView为UITableView? )

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; cell.editingAccessoryView = AccessoryView; AccessoryView.backgroundColor = [UIColor clearColor]; } 

我已经读过,你应该能够通过滑动来调用你自定义的editingAccessoryView,即使- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath返回“NO”。 但是这个我一直没能实现。

所以,总结一下吧。 我想我的editAccessoryView被显示在所有的单元格 – 如果可能的话,删除红色的圆圈。 或者,或者,当我滑动时调用我的editingAccessoryView – 当用户这样做时调用了什么方法?

任何帮助将非常感激。

我build议你inheritance表格单元格,并重写下面的方法

 - (void)layoutSubviews { if([self isEditing]) { // your custom stuff [self.contentView addSubview:myButton]; } } 

您需要为每个单元格创build一个新的附件视图。

而不是在cellForRowAtIndexPath ….中设置所有这些。

cellForRowAtIndexPath

 if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } 

并设置您的辅助视图

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source NSLog(@"Am I Editing"); UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; selectedCell.editingAccessoryView = AccessoryView; AccessoryView.backgroundColor = [UIColor clearColor] } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, // insert it into the array, and add a new row to the table view } } 

要删除红色圆圈,你可以返回UITableViewCellEditingStyleNone

 - (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath; 

但是在这种情况下,这个圈子的空间依然存在。 我几乎可以肯定,它也可以被删除。

我的问题是我的自定义EditingAccessoryView只出现在我第一次创build的单元格上

尝试实例化每个单元格的新AccessoryView而不是使用相同的一个。