开发者

How can I change the buttons in a UINavigationBar when my UITableView is editing?

I'd like to make my buttons in the UINavigationC开发者_如何学编程ontroller change from "back" and "edit" to "done" and "add" when the user hits "edit" and then change back when the user hits "done".

Which method should my UITableViewController implement?


I've figured this out, thanks to some Googling.

Here's my code:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing){
    [self.navigationItem setHidesBackButton:editing animated:animated]; 
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addSlide)];
    [self.navigationItem setLeftBarButtonItem:addButton animated:YES];
    [addButton release];
}else{
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    [self.navigationItem setHidesBackButton:editing animated:YES];  
} 
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜