我有这段代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[array removeObjectAtIndex:indexPath.row];
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)//OK button pressed
{
}
else if(buttonIndex == 1)//Annul button pressed.
{
}
}
我想在取消tableView
行之前显示提醒视图,然后将commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
的说明放在if
方法代表的第一个UIAlert
中...
有可能吗?
答案 0 :(得分:5)
将单元格的indexPath保存到ivar,并在警报视图调用的方法中使用该信息。
@interface MyClass : … {
NSIndexPath *deleteIndexPath;
}
@end
在您的实施中:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
deleteIndexPath = indexPath;
//code for UIAlrtView
// …
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)//OK button pressed
{
[array removeObjectAtIndex:deleteIndexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deleteIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}