我只是在 .h 文件中添加此方法:
- (IBAction)EditTable:(id)sender;
- (IBAction)DeleteButtonAction:(id)sender;
并在 .m 文件中:
(IBAction)DeleteButtonAction:(id)sender{
[表列表删除最后一个对象];
[表重新加载数据];
}
-
(IBAction)编辑表:(id)发送者{
if(自我编辑)
{
[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];
}
}
当我运行程序并单击删除按钮(红色按钮)时,程序停止!
有什么问题 ?请问有什么帮助吗?
你是邪恶的:(
好的,我的 .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];
}
}
我确信这肯定会帮助您从数组中删除包含数据的单元格。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)