在 tableView 中删除
Posted
技术标签:
【中文标题】在 tableView 中删除【英文标题】:delete in tableView 【发布时间】:2010-04-28 06:40:51 【问题描述】:我只是在 .h 文件中添加这些方法:
- (IBAction)EditTable:(id)sender;
- (IBAction)DeleteButtonAction:(id)sender;
在 .m 文件中:
(IBAction)DeleteButtonAction:(id)sender [tableList removeLastObject]; [表重载数据];
(IBAction) EditTable:(id)sender
如果(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];
当我运行程序并单击删除按钮(红色按钮)时,程序崩溃了!有什么问题 ?请帮忙?
【问题讨论】:
-1 用于延迟格式化和不遵守常见的 objc 样式。如果您需要帮助,至少让您的代码易于阅读! 【参考方案1】:如果我没记错的话,你想在点击删除按钮时删除 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];
我相信这肯定会帮助您从数组中删除包含数据的单元格。
【讨论】:
以上是关于在 tableView 中删除的主要内容,如果未能解决你的问题,请参考以下文章
无法从swift ios中的一段tableview中删除单元格