- (voID)tableVIEw:(UItableVIEw *)tableVIEw commitEditingStyle:(UItableVIEwCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UItableVIEwCellEditingStyleDelete) { UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Warning" message:@"Are you sure?" delegate:self cancelbuttonTitle:@"NO" otherbuttonTitles:@"YES",nil]; [alert show]; [self.array removeObjectAtIndex:indexPath.row];//or something similar to this based on your data source array structure [tableVIEw deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UItableVIEwRowAnimationFade]; }}- (voID)alertVIEw:(UIAlertVIEw *)alertVIEw clickedbuttonAtIndex:(NSInteger)buttonIndex{ Nsstring *Title = [alertVIEw buttonTitleAtIndex:buttonIndex]; if([Title isEqualToString:@"Nee"]) { NSLog(@"nothing to do here"); } else if([Title isEqualToString:@"Ja"]) { NSLog(@"Delete the cell"); }}
但是现在当我在单元格上向右滑动并且删除按钮出现时,我没有AlertVIEw.当我按下删除按钮时,我只获得AlertVIEw.当我按下删除按钮时,会出现消息,但单元格已被删除.
如何使这项工作?所以当我滑动时有一个AlertVIEw.
关于序列,一切都很好.只有在按下删除按钮时才会调用commitEditingStyle.关键是你实际上在响应警报之前删除了对象.把它改成这个:在@implementation之前将其添加到.m文件中:
@interface PutYourVIEwControllerClassnameHere@property (strong,nonatomic) NSIndexPath *indexPathTobedeleted;@end
然后:
- (voID)tableVIEw:(UItableVIEw *)tableVIEw commitEditingStyle:(UItableVIEwCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UItableVIEwCellEditingStyleDelete) { self.indexPathTobedeleted = indexPath; UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Warning" message:@"Are you sure?" delegate:self cancelbuttonTitle:@"NO" otherbuttonTitles:@"YES",nil]; [alert show]; // do not delete it here. So far the alter has not even been shown yet. It will not been shown to the user before this current method is finished. }}- (voID)alertVIEw:(UIAlertVIEw *)alertVIEw clickedbuttonAtIndex:(NSInteger)buttonIndex{ // This method is invoked in response to the user's action. The altert vIEw is about to disappear (or has been disappeard already - I am not sure) Nsstring *Title = [alertVIEw buttonTitleAtIndex:buttonIndex]; if([Title isEqualToString:@"NO"]) { NSLog(@"nothing to do here"); } else if([Title isEqualToString:@"YES"]) { NSLog(@"Delete the cell"); [self.array removeObjectAtIndex:[self.indexPathTobedeleted row]]; [self.tableVIEw deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPathTobedeleted] withRowAnimation:UItableVIEwRowAnimationFade]; }}
编辑:这应该编译,尽管可能有轻微的语法错误.一般说法:您只处理一个部分.至少只有删除内的一个部分是可能的.
总结以上是内存溢出为你收集整理的在删除UITableView单元格之前发出警报 – (UIAlertController)Swift或Objective-C全部内容,希望文章能够帮你解决在删除UITableView单元格之前发出警报 – (UIAlertController)Swift或Objective-C所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)