Ios 如何使用UIActionSheet确认UITableViewCell的删除
我有一个标准的CoreData/NSFetchedResultsController/UITableView设置。顶部没有“编辑”按钮,但右击一行将显示“删除”按钮。如果按下删除按钮,我想弹出一个UIActionSheet来确认删除 在UIActionSheet之前,我刚刚实现了tableView:CommittedItingStyle:ForRowatineIndexPath:并在其中为IndexXPath的managedObjectContext调用了deleteObject:,并让FetchedResultsController重写处理它的可视方面 现在,我有了tableView:CommittedItingsYOE:forRowAtIndexPath:创建UIActionSheet并显示它。我实现了actionSheet:ClickedButtonIndex:并在按下delete按钮的情况下放置deleteObject:。问题是我需要删除项目的indexPath,但它不再在范围内 我是不是 A在tableView:CommittedItingStyle:forRowAtIndexPath:中删除ManagedObject,然后在actionSheet:ClickedButtonIndex:中保存或回滚 B将索引路径存储为属性,以便我可以在tableView:CommittedItingStyle:ForRowatinIndexPath:中设置它,并在actionSheet:ClickedButtonIndex:中读取它 C还有别的 选项A似乎比必要的开销更大。无论哪种方式,它都会被删除,只是有时会回滚 选择B似乎非常强硬。这样的外部值似乎不太适合面向对象模型Ios 如何使用UIActionSheet确认UITableViewCell的删除,ios,uitableview,cocoa-touch,nsfetchedresultscontroller,uiactionsheet,Ios,Uitableview,Cocoa Touch,Nsfetchedresultscontroller,Uiactionsheet,我有一个标准的CoreData/NSFetchedResultsController/UITableView设置。顶部没有“编辑”按钮,但右击一行将显示“删除”按钮。如果按下删除按钮,我想弹出一个UIActionSheet来确认删除 在UIActionSheet之前,我刚刚实现了tableView:CommittedItingStyle:ForRowatineIndexPath:并在其中为IndexXPath的managedObjectContext调用了deleteObject:,并让Fetc
UIActionsSheet中是否有一个通用对象用于传入这样的值?还是我还遗漏了什么?我需要一个类似的解决方案。我通过创建一个ivar nsindepath*currentPath解决了这个问题;并对tableView使用了以下思想:CommittedItingStyle:forRowAtIndexPath:
如果用户点击delete按钮,我将从UITableViewCell中删除该行,并从数据源中删除该条目。如果他们点击cancel,我只会忽略该操作。我会将托管对象本身存储在-tableView:CommittedItingStyle:forRowAtIndexPath:method: 然后在-actionSheet:ClickedButtonIndex:中删除或不删除该对象,并在任何情况下设置self.deleteCandidate=nil 原因是获取的结果控制器对象可能会在调用的这两个方法之间发生变化 另一个选项是使用关联引用objc_setAssociatedObject、objc_getAssociatedObject来存储从UIActionSheet到相关对象的引用
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertView * alert;
UITableViewCell * cell;
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// save current indexPath
[currentPath release];
currentPath = [indexPath retain];
// display warning
alert = [[UIAlertView alloc] initWithTitle:@"Really?"
message:@"Are you really really sure you want to delete this item?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Delete", nil];
[alert show];
[alert release];
// clear delete confirmation from table view cell
cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setEditing:NO animated:NO];
[cell setEditing:YES animated:YES];
};
return;
}
self.deleteCandidate = [self.controller objectAtIndexPath:indexPath]