my application has uiwindow correctly set rootview controller. know because check rootviewcontroller after set (in app delegate), , well.
once app launches, works fine. issue rootview controller no longer set correctly on uiwindow when check in 'main' view.
my app works fine.. issue may wondering... well, trying implement adcolony (video advertising), need grab uiwindow's rotviewcontroller dislplay ad. when check rootviewcontroller... null.
i have added code check well.. , rootviewcontroller null.
how can uiwindow lose pointer rootviewcontroller? need understanding how uiwindow architecture works.
thanks
code checks uiwindow's visible controller (the below code returns nil viewcontrollers value.
uiwindow* window = [uiapplication sharedapplication].keywindow; uiviewcontroller* rootviewcontroller = [window rootviewcontroller]; [self getvisibleviewcontrollerchild:rootviewcontroller]; - (uiviewcontroller*)getvisibleviewcontrollerchild:(uiviewcontroller*)viewcontroller { uiviewcontroller* visibleviewcontroller = nil; if(!viewcontroller) { nslog(@"nil"); return nil; } if ([viewcontroller iskindofclass:[uinavigationcontroller class]]) { uinavigationcontroller* navigationcontroller = (uinavigationcontroller*)viewcontroller; viewcontroller = navigationcontroller.visibleviewcontroller; nslog(@"viewcontroller nav controller"); } while (visibleviewcontroller == nil) { if (viewcontroller.modalviewcontroller == nil) { visibleviewcontroller = viewcontroller; nslog(@"visibleviewcontroller = %@", visibleviewcontroller); } else { if ([viewcontroller.modalviewcontroller iskindofclass:[uinavigationcontroller class]]) { uinavigationcontroller *navigationcontroller = (uinavigationcontroller *)viewcontroller.modalviewcontroller; viewcontroller = navigationcontroller.visibleviewcontroller; nslog(@"modal 1"); } else { viewcontroller = viewcontroller.modalviewcontroller; nslog(@"modal 2"); } } } return visibleviewcontroller;
}
i can't figure out you're trying code, method keywindow seems returning nil, rootviewcontroller nil. i'm not sure why that's true, can rootviewcontroller (i assume you're doing view controller):
self.view.window.rootviewcontroller
Comments
Post a Comment