Ios 8開始從UIAlertView變成UIAlertController。
思路是在UIAlertAction的塊中刪除而不是在TableView的UItableviewRowAction中刪除(如果在這裏刪除會導致數據刪除後出現框提示)?
最終效果如圖所示:
在tableview上單擊按鈕時發生的事件。
-(NSArray & lt;UITableViewRowAction?* & gt?*)tableView:(UITableView?*)tableView?editActionsForRowAtIndexPath:(非空?NSIndexPath?*)索引路徑
{
//刪除
UITableViewRowAction?*刪除操作?=?【UITableViewRowAction?rowActionWithStyle:uitableviewroactionstyledestructive?標題:@“德爾”?handler:^(UITableViewRowAction?*?_Nonnull?行動,?NSIndexPath?*?_Nonnull?索引路徑)
{
【自我?askalert:indexPath.row?table index:index path];//只需在彈出的alertController中操作塊中的tableview即可。
}];
回歸?@[delete action];
}2.報警控制器塊
-?(作廢)?askalert:(NSInteger)delitem index?tableindex:(非空?NSIndexPath?*)索引路徑
{
_ _弱?_ _塊?XYZToDoListTableViewController?*tmp?=?自我;
UIAlertController?*警報?=?【UIAlertController?alertcontrollerwithttitle:@ " Tip "?留言:@ "是?妳呢。確定?”?preferred style:UIAlertControllerStyleAlert];
_ _塊?UIAlertAction?*取消?=?【UIAlertAction?actionwithttitle:@ "取消"?style:UIAlertActionStyleCancel?handler:^(UIAlertAction?*?_Nonnull?行動)?{
如果?(cancelAction)?{
}
}];
_ _塊?UIAlertAction?*確定操作?=?【UIAlertAction?actionwithttitle:@ " OK "?style:UIAlertActionStyleDefault?handler:^(UIAlertAction?*?_Nonnull?行動)?{
如果?(okAction)?{
//從列表數組中刪除數據
【tmp.toDoItems?removeObjectAtIndex:delItemindex];?
//刷新表視圖
【tmp.tableView?begin updates];
【tmp.tableView?deleteRowsAtIndexPaths:[n array?arrayWithObject:indexPath]?withRowAnimation:uitableviewroanimationautomatic];
【tmp.tableView?end updates];
【tmp?savedata:tmp . todo items];//存處
}
}];
【預警?addAction:cancel action];
【預警?addAction:ok action];
【tmp?presentViewController:alert?動畫:是嗎?完成:無];
}