2010-09-01 34 views
0

我想添加一个标题为“编辑”的UIBarButtonItem,当我点击“编辑”时,我可以选择要删除的行。 Apple API是否有简单的解决方案?或者我需要自定义制作UITableView和自己的操作?谢谢。在UITableView中进行多次编辑....

回答

0

你有2种选择:

  1. 自定义它就像你说的

  2. 添加UINavigationBar和使用UIVavigationItem,然后使用`self.editbuttonitem - >读到它here

+0

但是我该如何实现多重删除操作? 我可以检测到UITableViewCellEditingStyleDelete,但它只能检测到一个。 – DNB5brims 2010-09-01 07:07:08

+0

我不确定我了解你的问题。表格视图预先配置了在进入编辑模式时删除单元格的功能。有没有什么独特的,你试图实现? – Idan 2010-09-01 07:09:45

0

您是否继承UITableViewController?如果是这样的:

您需要的某个位置添加编辑按钮,如导航栏:

- (void)viewDidLoad 
{ 
    ... 
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 
    ... 
} 

而这个功能添加到您的视图控制器:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; // must be called first according to Apple docs 

    [self.tableView setEditing:editing animated:animated]; 
} 

你可能还需要设置表格行的编辑风格:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView.editing) 
    { 
     return UITableViewCellEditingStyleDelete; 
    } 
    else 
    { 
     return UITableViewCellEditingStyleNone; 
    } 
}