删除的tableView
问题描述:
我只是添加在.h文件中此方法:删除的tableView
- (IBAction)EditTable:(id)sender;
- (IBAction为)DeleteButtonAction:(ID)发送;
和.m文件:
(IBAction为)DeleteButtonAction:(ID)发送方{ [tableList removeLastObject]; [Table reloadData]; }
-
(IBAction为)EditTable:(ID)发送方{
如果(self.editing)
{
[super setEditing:NO animated:NO]; [Table setEditing:NO animated:NO]; [Table reloadData]; [self.navigationItem.leftBarButtonItem setTitle:@"Edit"]; [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
别的 {
[super setEditing:YES animated:YES]; [Table setEditing:YES animated:YES]; [Table reloadData]; [self.navigationItem.leftBarButtonItem setTitle:@"Done"]; [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
当我运行该程序,并单击删除按钮(红色按钮)的计划是停止! 最新的问题?请任何帮助?
你是邪恶:(
确定,再次我在.h文件中的代码是:
- (IBAction)EditTable:(id)sender;
- (IBAction)DeleteButtonAction:(id)sender;
和.m文件是:
- (IBAction)DeleteButtonAction:(id)sender{
[tableList removeLastObject];
[Table reloadData];
}
- (IBAction) EditTable:(id)sender{
if(self.editing)
{
[super setEditing:NO animated:NO];
[Table setEditing:NO animated:NO];
[Table reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
[super setEditing:YES animated:YES];
[Table setEditing:YES animated:YES];
[Table reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
} }
当我运行该程序并单击删除按钮(红色按钮)该程序崩溃!最新的问题?请任何帮助?
答
如果我没看错的,那么你要删除的tableView的细胞被点击删除按钮的时候....
你需要调用的tableview的另一个方法:
//To Delete the Data
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
// Updates the appearance of the Edit|Done button as necessary.
[super setEditing:editing animated:animated];
[tblViewBM setEditing:editing animated:YES];
// Disable the add button while editing.
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Use your Array from which you need to delete the data.
NSMutableDictionary *dict=(NSMutableDictionary *)[appDel.BookMarkAry objectAtIndex:indexPath.row];
type=[dict valueForKey:@"type"];
[appDel.BookMarkAry removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我当然这肯定会帮助你删除数组中的数据。
-1用于懒惰格式化和不遵守常见objc风格。如果您需要帮助,至少可以轻松阅读您的代码! – 2010-04-28 07:49:42