ios - presentViewController Warning view is not in the window hierarchy -
i loading launchviewcontroller
root view controller in appdelegate's application:didfinishlaunching
method:
uistoryboard *storyboard = [uistoryboard storyboardwithname:@"launchviewcontroller" bundle:nil]; launchviewcontroller *launchviewcontroller = [storyboard instantiateinitialviewcontroller]; launchviewcontroller.managedobjectcontext = [currentsession mainqueuecontext]; self.window.rootviewcontroller = launchviewcontroller; [self.window makekeyandvisible];
launchviewcontroller communicates web server fetch data. using afnetworking library asynchronous communication web server. in success callback after fetching data, presenting loginviewcontroller. understanding callbacks in case of afnetworking performed on main thread. nevertheless used performselectiononmainthread
see if resolve issue:
inside callback:
[self performselectoronmainthread:@selector(presentloginview) withobject:nil waituntildone:no];
presentloginview
method:
- (void)presentloginview { loginviewcontroller *loginviewcontroller = [[loginviewcontroller alloc] initwithnibname:@"loginviewcontroller" bundle:nil]; loginviewcontroller.managedobjectcontext = self.managedobjectcontext; [self presentviewcontroller:loginviewcontroller animated:yes completion:nil]; }
the login view not presented , in console see following message:
warning: attempt present <loginviewcontroller: 0x78e47c30> on <launchviewcontroller: 0x78eb4a60> view not in window hierarchy!
:-(
update put breakpoint in viewdidload, viewdidunload, viewwillappear , viewdidappear methods of loginviewcontroller. viewdidload hit. others not. why view loaded not appear?
that's happening because afnetworking execute callback fast, instance before view of view controller loaded, maybe because using local server or configuration in viewdidload slow. in case recommend move code viewwillappear or viewdidappear since in moment view in hierarchy , therefore able present viewcontroller there.
Comments
Post a Comment