本文介绍了UITableView某些行不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将UITableView配置为可编辑的.由于某些原因,当按下编辑按钮时,实际上只有某些行是可编辑的.

I've configured a UITableView to be editable. For some reason, when the edit button is pressed, only certain rows are actually editable.

并非所有用于删除行的红色可点击圆圈都是可点击的.

Not all of the red, tappable circles used to delete a row are tappable.

这是一个演示该问题的Quicktime视频.

如果您滑动行以将其删除(而不是从顶部的编辑按钮开始),则会发生相同的行为-有些行是可编辑的;有些不是.

The same behavior occurs if you swipe the row to delete it (instead of starting with the edit button at the top) - some rows are editable; some are no.

这是我遇到这种情况的事件序列:1.填充表格视图(例如2个项目)2.删除两个项目3.添加五项4.这些项中的三项将是可删除的-其他两项(等于最初填充表中的数字)将不可删除.

Here is the sequence of events under which I encounter this situation:1. Populate the tableview (with, say, 2 items)2. Delete both items3. Add five items4. Three of these items will be deletable - the other two (equal to the number initially populating the table) will not be deletable.

我有点困惑.任何帮助将不胜感激.谢谢!

I'm a little perplexed. Any help would be very much appreciated. Thanks!

推荐答案

在实现可食用的视图委托时,尝试将其添加到类中:

Try to add this to class, when you implement eatable view delegate:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
automaticEditControlsDidShow = NO;
[super setEditing:editing animated:animated];

if (editing) {
    automaticEditControlsDidShow = YES;
    [self.tableView insertRowsAtIndexPaths:addRow withRowAnimation:UITableViewRowAnimationLeft];
} else {
    [self.tableView deleteRowsAtIndexPaths:addRow withRowAnimation:UITableViewRowAnimationLeft];
}
}

或尝试实现您的 editingStyleForRowAtIndexPath 方法.例如:

Or try to implement your editingStyleForRowAtIndexPath method. For Example:

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

return UITableViewCellEditingStyleDelete;
}

这篇关于UITableView某些行不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:11