2014-01-07 33 views
1

我有一个TableView三个部分。第一节和第二节可以删除,(用滑动删除) 第三节不能。我现在的问题是,当我在第三部分的单元格上滑动时,它会被选中。当“canEditRowAtIndexPath”被调用(并且它真的被调用)时,我尝试取消选择它,但那不起作用,并且单元格保持选中状态。我的 “canEditRowAtIndexPath” 看起来是这样的:在不可删除的行上滑动后取消选择单元格

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; 

    if (indexPath.section == 2) 
    { 
     return NO; 
    } 
    return YES; 
} 

回答

0

此委托方法我发现了一个伟大的解决方法关闭-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath第3节单元格的选择。 在单元格上滑动,强制应用程序调用viewWillAppear。 将[self.tableView reloadData];添加到该方法中,并且选定的状态将被删除。

0

你应该叫[self.tableView deselectRowAtIndexPath:indexPath animated:NO];在这种方法 -

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

还是在 -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 集选择的风格没有。 cell.selectionStyle = UITableViewCellSelectionStyleNone;

+0

didSelectRowAtIndexPath在我滑过单元格时未被调用...如果您只是轻扫,则不会选择,但单元格会突出显示 –

1

您可以检查,并通过使用tableViewCell.selectionStyle = UITableViewCellSelectionStyleNone;

0

使用UITableView

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
1

我发现(在我opnion)较好地解决了这个问题

self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Right) 

我希望帮助! Regards

相关问题