在我的UITableView
中,当它进入编辑模式时,我只想选择一些选定的单元格。我知道UITableView
班有财产allowsSelectionDuringEditing
,但这适用于整个UITableView
。我没有看到任何相关的委托方法在每个单元的基础上进行设置。UITableView编辑时的单元格选择模式
我能想出的最佳解决方案是将allowsSelectionDuringEditing
设置为YES
。然后,在didSelectRowAtIndexPath
中,如果表视图正在编辑,则过滤掉任何不需要的选择。另外,在cellForRowAtIndexPath
中,将这些单元格selectionStyle
更改为无。
问题是进入编辑模式不会重新加载UITableViewCells
,所以他们的selectionStyle
直到他们滚动离屏时才会更改。所以,在setEditing中,我还必须迭代可见单元格并设置它们的selectionStyle
。
这有效,但我只是想知道是否有更好/更优雅的解决方案来解决这个问题。我的代码的基本轮廓附加。任何建议非常感谢!谢谢。
- (void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
if (self.editing && ![self _isUtilityRow:indexPath]) return;
// Otherwise, do the normal thing...
}
- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
// UITableViewCell* cell = ...
if (self.editing && ![self _isUtilityRow:indexPath])
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
return cell;
}
- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing)
{
for (UITableViewCell* cell in [self.tableView visibleCells])
{
if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
}
else
{
for (UITableViewCell* cell in [self.tableView visibleCells])
{
if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
}
}
}
您可以在进入编辑模式时重新加载表格,或者在选择该表格后立即取消选择该行,而不是将选择样式设置为无... – AMayes 2013-01-10 21:29:11