ios - unrecognized selector sent to instance when accessing content from another tab bar controller -
ios - unrecognized selector sent to instance when accessing content from another tab bar controller -
i have app 3 tab bar controllers: map, favorite , setup
the map view controller has flag set in setup view controller. navigate between these 3 controller using tab bar.
in map.h file:
@interface mapviewcontroller : uiviewcontroller <mkmapviewdelegate> { } @property (nonatomic) bool flag;
in map.m file:
@synthesize flag = _flag;
in setup.h file:
@interface setuptableviewcontroller : uitableviewcontroller <uitabbarcontrollerdelegate> { } @property (nonatomic) bool config; @property (retain, nonatomic) mapviewcontroller *mapvc;
in setup.m file seek read flag set in map view controller can set display accordingly. ease of debugging simplified crash next code:
- (void)viewdidload { [super viewdidload]; self.tabbarcontroller.delegate = self; //grab pointer first tab bar controller can configuration self.mapvc = (mapviewcontroller *) [self.tabbarcontroller.viewcontrollers objectatindex:0]; if (self.mapvc) { nslog(@"viewdidload setuptvc showcelcius %d", self.mapvc.flag); //crash } }
2014-06-19 13:36:44.495 myapp[25505:60b] -[uinavigationcontroller flag]: unrecognized selector sent instance 0x10d43f340 2014-06-19 13:36:44.497 myapp[25505:60b] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[uinavigationcontroller flag]: unrecognized selector sent instance 0x10d43f340'
its because first object of self.tabbarcontroller.viewcontrollers uinavigationcontroller. think mapvc embedded in uinavigationcontroller. check that.
if so, :
uinavigationcontroller *mapnc = self.tabbarcontroller.viewcontrollers.firstobject; self.mapvc = (mapviewcontroller *)mapnc.viewcontrollers.firstobject; ios objective-c uitabbarcontroller
Comments
Post a Comment