开发者

iphone connecting code to the 'back' button

Is there a way to connect code to a view's 'back' button that is part of a navigation controller? That back button is automatically coded in by the nature of it being a navigation controller so I am not sure how I can connect code to it.

(I know this sho开发者_运维知识库uld be really easy but I can't seem to find it in the documentation on navigation controller.)


viewWillDisappear is where you would typically add code to execute when the back button is pressed


In reality you should not have a code that needs to be executed when Back button is pressed. What exactly you're trying to achieve?


You could check if the controller was popped in viewWillDisapper, like in this example:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        // back button was pressed.  We know this is true because self is no longer
        // in the navigation stack.
        NSLog(@"Article done");
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜