在tableView中删除 [英] delete in tableView

查看:94
本文介绍了在tableView中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在.h文件中添加此方法:

I just add this methods in .h file :

- (IBAction)EditTable:(id)sender;

- (IBAction)DeleteButtonAction:(id)sender;

- (IBAction)DeleteButtonAction:(id)sender;

和.m文件:


  • (IBAction)DeleteButtonAction:(id)sender {
    [tableList removeLastObject];
    [表格重新加载];
    }

  • (IBAction)DeleteButtonAction:(id)sender{ [tableList removeLastObject]; [Table reloadData]; }

(IBAction)EditTable:(id)发件人{

(IBAction) EditTable:(id)sender{

如果( self.editing)

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
{

else {

[super setEditing:YES animated:YES];
[Table setEditing:YES animated:YES];
[Table reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];

}

}

当我运行程序并单击删除按钮(红色按钮)时程序停止!
是什么问题?请帮忙吗?

when I run the program and click the delete button (red button) the program is stop ! whats the problem ? please any help ?

你是邪恶的:(

好的,我的.h文件中的代码是:

OK, again my code in .h file is :

- (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];
} }  

当我运行程序并单击删除按钮(红色按钮)时程序崩溃!有什么问题 ?请帮忙吗?

when I run the program and click the delete button (red button) the program is crash ! whats the problem ? please any help ?

推荐答案

如果我没有错,那么你想在单击删除按钮时删除tableView的单元格。 ...

If I am not wrong then you want to delete the cell of the tableView when delete button is clicked....

您需要调用另一种tableview方法:

You need to call one other method of 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];
 } 
}

我相信这肯定会帮助你删除包含数组数据的单元格。

I am sure this will Definately help you to delete the cell with data from array also.

这篇关于在tableView中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆