ios - Can I detect taps on a controller's tab without being its delegate? -
i've written container controller i'm using inside tab bar controller. container manages stack of controllers uinavigationcontroller, , i'd behave same way navigation controller does, when tab tapped while selected container pops root controller.
i'm not looking solution involves being tab controller's delegate; want container behave same way uinavigationcontroller , automatically when put inside tab controller.
update: respond of scepticism, hoping there might undocumented method uitabbarcontroller calls on uinavigationcontroller implement; however, having put logging in -respondstoselector: method i've seen -_appearancecontainer. however, putting logging in -iskindofclass: shows it's being tested against uinavigationcontroller in several places.
i think found way. tested on navigation controller, think work on custom controller well. use kvo in custom container controller.
- (void)viewdidload { [super viewdidload]; [self addobserver:self forkeypath:@"self.tabbarcontroller.selectedviewcontroller" options:nskeyvalueobservingoptionnew | nskeyvalueobservingoptionold context:nil]; } - (void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context { if ([change[@"old"] isequal:change[@"new"]] && [change[@"new"] isequal:self]) { nslog(@"nav controller's tab selected again"); }else{ nslog(@"different tab selected"); } }
Comments
Post a Comment