开发者

Multiple edit in UITableView....

I would like to add a UIBarButtonItem which is titled "edit", when I click the "edit", I can select the row to delete. Is there any simple solution on Apple API开发者_如何转开发 already? or I need to customize made the UITableView and the action myself? thank you.


You have 2 options :

  1. Customize it like you said

  2. Add a UINavigationBar and use UIVavigationItem , and then use `self.editbuttonitem -> read about it here


Are you subclassing UITableViewController? If so:

You need to add an edit button somewhere, like the navigation bar:

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

And add this function to your view controller:

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

You probably also want to set the editing style for the table row:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜