You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Problem With UINavigationBar:didPopItem

Even though I've defined my class as UINavigationBarDelegate didPopItem is not being called ?

any body have this resolved ?

MacBook 2.4 GHz, Mac OS X (10.5.6)

Posted on Apr 1, 2009 8:16 PM

Reply
4 replies

Apr 2, 2009 2:40 AM in response to Rob Cy

Hi Rob. Are any of the other nav bar delegate methods being called (e.g. shouldPushItem or shouldPopItem)? Are you using a nav controller? The UINavigationBarDelegate methods will only be called if you're using a nav bar without a nav controller. In fact I don't think there's any way to manually set the delegate property of a nav bar which is managed by a nav controller.

If you don't have a nav controller, make sure you set the nav bar delegate property to the object where didPopItem is defined. Remember that an instance of a class which conforms to the UINavigationBarDelegate protocol doesn't automatically become the nav bar's delegate. Also check for a typo in the method name. didPopItem is optional, so the compiler won't warn you if it's misspelled. Recently I didn't capitalize one of the letters in the id of an optional delegate method and it took forever to find the problem. The name looked correct to me no matter how long I looked at it. Sometimes I paste delegate names from the docs just to be sure.

Apr 2, 2009 11:59 AM in response to RayNewbie

Hi Ray,
Thanks for your response, yes I have a navigation controller, so you mean there is now way to trap this event if we have a navigation controller ? Actually in my application delegate code I create a UITabView with two UINavigationController for two tabs and I assign tabs to portrait window then my UIViewController are assigned to UINavigationController then I defined the UIViewController as UINavigationBarDelegate and put that didPopItem function inside the UIViewController, so with this layout I am not sure if I can trap that event .

Apr 2, 2009 1:22 PM in response to Rob Cy

Well there's no way to get didPopItem to be called without setting the nav bar's delegate property. I haven't found where the docs explicitly say you can't set the bar's delegate, but the UINavigationController reference says this:

+Although, navigation controller uses a navigation bar in its implementation, you should never need to, nor should you, access the navigation bar directly. You can, however, access the navigation items that represent the appearance of your view controllers.+

I made a test bed to verify this and found that when I set a controlled tab bar's delegate property in either code or IB, I get a run time crash. For example, this code added to the NavBar sample app will crash:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// add the navigation controller's view to the window
[window addSubview:[navigationController view]];
UINavigationBar *navBar = [navigationController navigationBar];
MainViewController *mainViewController = (MainViewController*)[navigationController topViewController];
// how can we set the delegate if we don't "access the navigation bar directly"?
[navBar setDelegate:mainViewController];
[window makeKeyAndVisible];
}

2009-04-02 12:57:49.119 NavBar[53368:20b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot manually set the delegate on a UINavigationBar managed by a controller.'

I've found that answering questions with bad news is a thankless job 😟 but bottom line: No, there's no way to trap the event when we have a nav controller.

Problem With UINavigationBar:didPopItem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.