Tuesday 15 April 2014

ios - How to set delegate on CustomToolbar in rootViewController using a NavigationController setup with initWithNavigationBarClass:toolbarClass: -



ios - How to set delegate on CustomToolbar in rootViewController using a NavigationController setup with initWithNavigationBarClass:toolbarClass: -

how set delegate customtoolbar in rootviewcontroller when using navigationcontroller setup initwithnavigationbarclass:toolbarclass:

in code doing following:

rootviewcontroller *rootviewcontroller = [[rootviewcontroller alloc] initwithclassname:kftpostclasskey]; uinavigationcontroller *navcontroller = [[uinavigationcontroller alloc] initwithnavigationbarclass:[customnavigationbar class] toolbarclass:[customtoolbar class]]; [navcontroller setviewcontrollers:@[rootviewcontroller] animated:no]; // nowadays home view controller [self presentviewcontroller:navcontroller animated:yes completion:null];

in 'rootviewcontroller' trying set delegate toolbar in order observe when item tapped.

[self.navigationcontroller.toolbar setdelegate:self];

when exception:

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'cannot manually set delegate on uitoolbar managed controller.'

i looked @ documentation , learned can not set delegate when toolbar beingness managed uinavigationcontroller. question this: how can observe clicks on customtoolbar in rootviewcontroller if can not set delegate?

i appreciate deeper explanation, new , not sure how working.

my guess in order work, navigationcontroller needs navigationbar delegate. that's why can not set navigationbar delegate when used in navigationcontroller.

as utilize subclass of navigationbar, can seek have subprotocol of uinavigationbardelegate in add together navigationbarwasselected method. in new uinavigationcontroller subclass, implement method allow rootviewcontroller when navigation clicked.

or, in custom navigation bar can send nsnotification in nsnotificationcenter, , grab in rootviewcontroller.

ios objective-c uinavigationcontroller delegates uitoolbar

No comments:

Post a Comment