Viewwillappear called but viewdidappear not called - iphone

the viewwillappear is called in my viewcontroller but for some reason the viewdidappear is not called.
I am showing the view by calling the navigatorcontroller push method.

I encountered this problem on ios5 system and guessed apple change the view invoke method.
Maybe you can try to write the same code in both viewwillappear and viewdidappear.

Related

How to fix the warning: view is not in the window hierarchy

I'm using the standard setup procedure for Mobclix in an iOS app and I'm calling the requestAndDisplayAdFromViewController: method from within viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[fullScreenAdViewController requestAndDisplayAdFromViewController:self];
}
here's the warning I'm getting:
Warning: Attempt to present <MobclixFullScreenAdViewController: 0x14f2c0> on <EditGameViewController: 0x1838d0> whose view is not in the window hierarchy!
I hope that's enough to go on. thanks for any help.
You're calling it from viewWillAppear - at this point, the view is not necessarily in the hierarchy yet (it WILL appear, doesn't mean it has appeared yet). Try calling it from viewDidAppear, which is called when the view is confirmed to be in the hierarchy.
Try to move your code [fullScreenAdViewController requestAndDisplayAdFromViewController:self]; to viewDidAppear.
You can also try to display the view in the viewDidLoad method.
You should try moving this code to viewDidAppear.
From the Apple documentation on viewWillAppear:
This method is called before the receiver’s view is about to be added to a view hierarchy

In iPhone, is it guaranteed that viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear are always called?

I'm using viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear of UIViewController.
And I use UINavigationController to navigate view controllers.
For example, I create NSTimer or register notifications in viewWillAppear or viewDidAppear. And I invalidate the timer or remove notifications in viewWillDisappear or viewDidDisappear.
But if those 4 methods (viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear) are not called, the program will crash or retain cycle will happen.
I couldn't find the documentation saying that it is guaranteed that viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear are always called.
Till now, they seem to be always called and my program works as I expected.
But are there cases that the 4 methods are not called?
Or is it possible the 4 methods are usually called but sometimes not called randomly with no reason?
I can say than viewWillAppear and viewDidAppear methods are always called in your view.
viewWillDisappear and viewDidDisappear methods are called when you change your view with another one or close it. If you have some scrolling views for example, these methods won't be called.
Yes, they are always called. Just make sure to call the superclass implementation if you subclass one of your view controllers.
I think you can trust those methods, still, viewDidLoad and dealloc for me never failed.
You can register and remove notifications there. But, I don't know all of your app specifications and what I recommend might not be viable.
Yes the View events always fire, however to override the behaviour you must declare them.
According to apple documentation viewDidUnload is deprecated.
Look at this link for the official apple class reference for UIViewController
UIViewController Reference
It states:
The UIViewController class provides specific methods that are called when these events occur. Subclasses can override these methods to implement specific behaviors.
Here are the same thread in which same thing asked m any times
you can view these here
here the first link
here the second one
Aside from bugs when some of the methods may not get called and/or called twice (e.g. dismissing/popping several controllers at once), with iOS 7, if you initiate the swipe-to-back gesture, partially revealing the previous controller in the navigation stack, and then cancel the swipe-to-back, so that no popping occurs, you will observe that not all of the methods get called on both of the controllers.

ViewWillAppear on iPad

my question is that i use ios 4.1 and viewWillAppear is not call when i go via
[self.view addSubView:self.mySecondView.view];
then and in the first view i alloc second view on ViewDidLoad .. i just want to call ViewWillApear on Second View because want to do the task dynamic.
is their some thing alternative... because InitWithNibName method also fire when alloc and init occur.. i want to fire some method when i add to that view.
Thanks
The same issue is discussed before,Just go through below SO links.
iPhone viewWillAppear not firing
viewDidLoad gets called, viewWillAppear does not get called, view does not appear on screen
http://forums.macrumors.com/showthread.php?t=575530
here is the tutorial post
http://www.idev101.com/code/User_Interface/UINavigationController/viewWillAppear.html

presentModalViewController calling any method in the target viewController?

When i call presentModalViewController
[self presentModalViewController:iPSPvc animated:NO];
is there a method i can implement in the target viewController (iPSPvc) that gets called every time this happens?
I need to make sure some updating of the view is done.
viewDidLoad gets called when i create an instance of iPSPvc so I need a method where I can do sometime similar.
Many Thanks
-Code
Try viewWillAppear method
-(void)viewWillAppear:(BOOL)animated
{
//your code goes here
}
what's with viewWillAppear and viewDidAppear?
- (void)viewWillAppear:(BOOL)animated
If I've understood your question aright, the above method (or one its close cousins) in your target viewController. This gets called every time the controller's view is about to appear, not just when the view is first loaded.

willRotateToInterfaceOrientation not being called

I'm returning YES in my view controller's shouldAutorotateToInterfaceOrientation function, and I can see using breakpoints that YES is being returned, however the willRotateToInterfaceOrientation method isn't being called, and nor is any other rotating method. It seems like after returning YES nothing happens!
Any ideas?
Mike
Is this views viewController a subview of some other root view controller thats not a navigation controller? if so then the call does not propagate to the subviews controller, so that might be why your view isnt rotating.
I have a similar problem and saw Daniel's answer however I can't find any confirmation of this in the developer documentation. Not that I don't believe the answer but I don't really understand why the orientation call does not propagate.
Someone gave me a trick that works using something like this:
[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(detectOrientation) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
One thing to look for is I found if I had UIPopoverController called in [UINavigationController viewDidAppear], then willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are not called. It looks like UIPopoverController being modal blocks the rotation method calls.
Yes me too. Ok, it won't get called in a sub-viewcontroller - have to pass it down. Can deal with that. And the notification idea works well except that you only get "did..." not "will..." (afaik) and anyway it's a messy solution to a problem which shouldn't be there.
My mistake was to call [super loadView] in my loadView. Not supposed to do that. When I removed [super loadView] and alloc'd the view myself willRotateToInterfaceOrientation started working.
What's really weird is that the [super loadView] was in the sub-viewcontroller and the event wasn't even reaching the top one...
If you are not receiving callbacks on willAutoRotateToInterfaceOrientation in any view controller, add the view controller as your root view controller's child view controller.
For Eg; say self.viewController is your root view controller and childViewController is the view controller in which you want to get auto-rotation callbacks, add the following line of code;
[self.viewController addChildViewController:childViewController];
Actually, adding as the child view controller to any view controller which gets rotation call backs will work too.
Hope it helps.
Apple documentation
At launch time, apps should always set up their interface in a portrait orientation. After the application:didFinishLaunchingWithOptions: method returns, the app uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window.
So if you are using a TabBarViewController be carefull to set up the selected view in the application:didFinishLaunchingWithOptions: method.