开发者

iPhone: capturing back button event

Greetings,

I have the following code for capturing the back button's event:

[self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(doLogout:)]];

And here is my doLogout:

-(void) doLogout:(id)sender{
    NSLog(@"hi");
}

Everything compiles and runs fine, and the back button text is changed to "Logout".

The only problem is that my doLogout function is never called!!!

What can I do? I've been stu开发者_JAVA百科ck on this for an hour now... ;(

Many thanks in advance,


The official doc:

When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title.


Instead of trying to catch "back button event" why no just just try overriding UIViewController viewDidUnload?


Instead of setting backBarButtonItem on the top view controller, what you could do is set the leftBarButtonItem on the child view controller. This can be any arbitrary bar button item and all action messages should be delivered as normal. Because this takes place of the back button, you have to make sure you manually pop the child controller in one of the action methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜