开发者

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

开发者 https://www.devze.com 2023-01-28 22:49 出处:网络
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 hit

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

精彩评论

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