我有一个项目,我一直在努力。代码给我的问题昨天工作,我没有做任何改变的代码的部分,因为,当我试图运行它今天它无法正常工作。Xcode commitEditingStyle UITableViewCellEditingStyleDelete不工作
问题是,当我滑过单元格以删除它时,未检测到它,并且commitEditingStyle方法从不运行。
我也做了另一个项目只是为了测试commitEditingStyle方法,它工作正常。我还清理了项目(产品 - >清洁)并重置了iOS模拟器。
我还能试试吗?
这是我的代码,不用担心NSUserDefaults,这是为了在删除单元格后保存更改。
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES; }
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.taskObjects removeObjectAtIndex:indexPath.row];
NSMutableArray *newTaskObjectsData = [[NSMutableArray alloc] init];
for(Model *task in self.taskObjects)
{
[newTaskObjectsData addObject:[self taskObjectAsPropertyList:task]];
}
[[NSUserDefaults standardUserDefaults] setObject:newTaskObjectsData forKey:USER_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
它仍然没有工作,问题是当用户在单元格上滑动时,方法commitEditingStyle永远不会被调用。 – Ben