• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iOS: preventing popping nav controller
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iOS: preventing popping nav controller


  • Subject: Re: iOS: preventing popping nav controller
  • From: Rick Mann <email@hidden>
  • Date: Mon, 12 Mar 2012 20:09:39 -0700

On Mar 12, 2012, at 18:57 , Roland King wrote:

> If you really hate that, not sure what you can do. What was your idea for subclassing UINavigationController? I didn't instantly see a place to hook in without messing with the navigationBar delegate, something the documentation tells you not to do (although I'd probably try that anyway).

My subclass implements one method, the UINavigationBar delegate method:

- (BOOL)
navigationBar: (UINavigationBar*) inNavigationBar
    shouldPopItem: (UINavigationItem*) inItem
{
    bool shouldPop = true;
    UIViewController* vc = self.topViewController;
    if ([vc respondsToSelector: @selector(navigationControllerShouldPop:)])
    {
        shouldPop = [vc performSelector: @selector(navigationControllerShouldPop:) withObject: self];
    }

    if (shouldPop)
    {
        //  UINavigationController doesn't declare it's a delegate, so we
        //  have to do this ugliness…

        BOOL (*f)(id, SEL, ...) = [UINavigationController instanceMethodForSelector: _cmd];
        shouldPop = f(self, _cmd, inNavigationBar, inItem);
    }

    return shouldPop;
}


The call to + instanceMethodForSelector: is required because UINavigationController doesn't actually declare it's a delegate, and I can't just call super.

Any top view controller that implements -navigationControllerShouldPop: will get called.

This seems to work. I may end up changing the buttons after all, but this'll do for now.

--
Rick


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >iOS: preventing popping nav controller (From: Rick Mann <email@hidden>)
 >Re: iOS: preventing popping nav controller (From: Roland King <email@hidden>)
 >Re: iOS: preventing popping nav controller (From: Rick Mann <email@hidden>)
 >Re: iOS: preventing popping nav controller (From: Roland King <email@hidden>)

  • Prev by Date: Re: iOS: preventing popping nav controller
  • Next by Date: Re: Sudden and hard to reproduce crashes in libcache
  • Previous by thread: Re: iOS: preventing popping nav controller
  • Next by thread: Re: Sudden and hard to reproduce crashes in libcache
  • Index(es):
    • Date
    • Thread