UIAlertView 确认删除按钮
UIAlertView confirm delete button
我有一个tableview
,还有一个删除功能。现在我想要一个带有确认的 UIAlertView
。
这是我现在拥有的代码:
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
AgendaModel* agenda = _meeting.agenda[indexPath.row] ;
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:agenda.id,@"id",agenda.name,@"name", nil];
NSString *message = [NSString stringWithFormat:@"Are you sure that you want to delete : %@?", agenda.name];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
message:message
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:@"Delete", nil];
[alert show];
}
}
它给了一个弹出窗口,但因为我没有说要删除它所以不起作用。我希望我的应用程序在按下删除按钮后执行此代码:
NSString *delete_url = [NSString stringWithFormat:@"RestAgendas/delete.json"];
[_meeting.agenda removeObject:agenda];
[self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[JSONAPI getWithPath:delete_url andParams:dict completion:^(id json, JSONModelError *err) {
NSLog(@"%@", json);
}];
我在哪里可以定义 UIAlertView
中按钮的操作?
不好意思问题乱七八糟,希望大家理解我的意思
您应该避免使用 AlertView(已弃用)并切换到 UIAlertController。
它更通用,取代了旧的 alertView 和 actionSheet。
查看 documetation
和 tutorial in swift or tutorial in objC.
我有一个tableview
,还有一个删除功能。现在我想要一个带有确认的 UIAlertView
。
这是我现在拥有的代码:
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
AgendaModel* agenda = _meeting.agenda[indexPath.row] ;
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:agenda.id,@"id",agenda.name,@"name", nil];
NSString *message = [NSString stringWithFormat:@"Are you sure that you want to delete : %@?", agenda.name];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
message:message
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:@"Delete", nil];
[alert show];
}
}
它给了一个弹出窗口,但因为我没有说要删除它所以不起作用。我希望我的应用程序在按下删除按钮后执行此代码:
NSString *delete_url = [NSString stringWithFormat:@"RestAgendas/delete.json"];
[_meeting.agenda removeObject:agenda];
[self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[JSONAPI getWithPath:delete_url andParams:dict completion:^(id json, JSONModelError *err) {
NSLog(@"%@", json);
}];
我在哪里可以定义 UIAlertView
中按钮的操作?
不好意思问题乱七八糟,希望大家理解我的意思
您应该避免使用 AlertView(已弃用)并切换到 UIAlertController。 它更通用,取代了旧的 alertView 和 actionSheet。 查看 documetation 和 tutorial in swift or tutorial in objC.