iphone view controller methods not being called but view shows - iphone

I have a navigation controller with a UITableView which when goes to another view when a row is selected. When this loads the breakpoints get hit.
Good so far.
When I hit the back button, the table view appears fine, with data.
However, even though I have breakpoints enabled in the viewcontroller, none get hit like when it originally loaded! But yet, the data loads fine. The only breakpoint that registers now is when I click on a row (didSelectRowAtIndexPath).

Where are the breakpoints set that you are expecting it to break?
Perhaps you need to call the following in the viewWillAppear method...
[self.table reloadData];

It would depend on where your breakpoint is actually located. If you have a breakpoint in viewDidLoad method, then it will only be called once when the view is first created. When you go back from another view, the view is not loaded again. So the breakpoint will not hit. However, viewWillAppear method will be called.

You are using a navigation controller here. Navigation controller holds a navigation stack, which includes UIViews on top of each other, with the visible one on the top.
Now, let's say the table view was loaded, then you move to another (which is now the topmost view in the navigation stack). Note - the table view is not gone. It's there, just under the view you are currently presenting.
Thus, when you move back to the table view, it is not reloaded, because it was never gone (released), just hidden.
There are exceptions to the above, and sometimes a view which is not presented on screen will be released (low memory scenarios situations, for example), but you can't count on it.
The UINavigationController Class Referance explains this concept very well.

Related

why only viewWillAppear called on navigation back

I have doubt need to be clear.. I have stack and a navigation controller.now when the stack loads the viewDidLoad viewWillAppear viewDidAppear will be called. when i click some button then this button push me to the new stack , now new stack gives me the option of the back..now when i click on the back of the navigation controller..why only viewWillAppear will be called ..why not viewDidLoad and not viewDidAppear
Stack is Last In First Out (LIFO), so when you push new view controllers to the stack, previous viewcontroller will not get destroyed( and they remain in memory). When you pop back, there is no need to recreate the Viewcontroller since it is already in memory. So only viewWillAppear gets called.
As to why viewDidAppear doesn't get called in this case, I cant remember where I have read this, but viewDidAppear gets called after your UIViewController's view was added to the application's UIWindow heirarchy. And this process is done before the UIViewController is shown for the first time.
viewDidLoad only called when viewControllers views are loaded into the memory. It will be done when
the first time the view is needed to be shown
sometimes when viewController needed to be reloaded again, because
it is purged from memory for some low memory reason.
In your case, when you pop back, the viewController is already loaded, so no need to call viewDidLoad again.
Full life cycle of ios ui explain here.
http://www.verydemo.com/demo_c134_i4568.html
Note By Abizern from comment: this is true for iOS5 and earlier. iOS6 does not unload views anymore.
First of all, nice question #user2102546. Checkout here the perfect reason for your query.
viewDidLoad only gets called if view controller's views were unloaded, and need to be reloaded.
Normally, if you use a navigation controller, and go back to a previous view with one of the pop methods, viewDidLoad does not get called again, because the view are not unloaded yet.
However, the system can unload the views of any view controller when it is not frontmost in order to free up memory, so viewDidLoad can get called any time a view controller is about to be presented. You need to write your code to respond correctly to the different events.
Enjoy Programming!!
I don't have a complete answer for you but I hope this helps.
viewDidLoad is a callback for modifying a view after the load event has happened. In your case, the view has already loaded. The fact that it is not in view doesn't mean it has been unloaded from memory.
viewDidAppear: While I don't know why this event isn't firing and would be happy if someone else would fill in the gap.

iPhone Storyboard, programmatically calling segues, navigation issues

So I have an iPhone app. It has a simple structure, all based on a UINavigationController.
I have a storyboard that has one view, a segue to another view, etc. Now this other view has a UITextView that I do not want to edit on this screen - if the user taps this, I want it instead to fly over to a second screen which basically has the same text view, but this one is full-screen, and the user will edit the text on that screen before returning to the previous screen.
So I capture the textViewShouldBeginEditing method. I previously, in the storyboard editor, manually created a push segue from the previous view controller to this new view controller, and named it so that I can call it by it's identity, which I do with:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
// This is called when the user clicks into the textView as if to edit it.
// Instead of editing it, go to this other view here:
[self performSegueWithIdentifier:#"editMemoSegue" sender:self];
// Return NO, as I don't actually want to edit the text on this screen:
return NO;
}
Seems reasonable. And it works. Sorta. It does in fact shoot me over to that other view. That other view's events fire up, I set it's text view to become first responder, I edit the text on that screen. Everyone's happy.
Until I want to use the back button to return to the previous view.
Then I quickly find out - my navigation stack is foobared. Most of the time, I have, for some reason, TWO instances of my new editing controller on the stack, so the first time I hit the back button I get the same stuff over again. Then, oddly, occasionally, it will work as intended, and I will see my previous controller with only one back click.
I started reading the log, and I found this:
2012-12-09 09:41:03.463 APP[8368:c07] nested push animation can result in corrupted navigation bar
2012-12-09 09:41:03.818 APP[8368:c07] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-12-09 09:41:03.819 APP[8368:c07] Unbalanced calls to begin/end appearance transitions for <SecondController: 0x83881d0>.
So obviously, I'm doing something incorrectly here. The question is, what? And how do I do what I want in the way that correctly appeases the tiki gods of the iPhone framework?
Check to see if the textViewShouldBeginEditing is being called twice. I've noticed that these kinds of delegate calls sometimes are.
How is your #"editMemoSegue" being created on the storyboard? is it created from the textView? if it is then you should recreate it directly from the view controller or from the top status bar on the view controller that way it wont be called twice when you touch the trigger object and when you call it programmatically.

UITabViewController, viewWillAppear does not invoked?

New to iOS, kindly bare if the question is very basic? When I press the tab button multiple times, it is not invoking viewWillAppear function? If I am wrong, then which function gets invoked, each time a tab button is pressed being on the same tabview?
You are correct, viewWillAppear is a little special, it is usually called automatically but in some cases including when you are adding a view controllers view manually (view addSubview:), and also when adding this as a view controller to a UITabViewController it doesn't get messaged.
This however is only for the root view, as you navigate (maybe with a navigation controller) back and forth, that root view's viewWillAppear will get triggered as some point.
In short, if you need to implement something in viewWillAppear in these cases, you should message it yourself when you know it's going to be presented. You can handle this case in your view controller, check out the following article about the matter:
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
Good luck.

iPhone viewDidAppear stops firing after loading/dismissing a modal view

I'm starting to go a little crazy with this one.
I have an iphone application with a somewhat complex view structure it is a tabbed application with either a view controller or a navigation controller on each tab.
The main controller for one tab uses the viewDidAppear callback to reload any data that has been modified since the last time it was displayed and this behaves fine in most cases. The issue I have run into is that when I navigate in subviews(within the same tab) using the standard navigation controller push/pop mechanism the viewWillAppear and viewDidAppear on the main view always fire when I navigate back to it.
However if I load a modal view controller and then dismiss it, the viewWillAppear continues to fire but the viewDidAppear stops firing.
I am almost certain that this is tied to the need to manually call these callbacks on the modal controller but I cannot find the reference info on how to do this correctly. (I only see this viewDidAppear bug on the hardware, in the simulator it works as I'd expect)
If you need further clarification let me know and thanks for any input.
Yes, this is how it works. You are better off switching to using viewWillAppear.
This has the added advantage of updating the data before the screen is redrawn.
viewDidLoad should be used for one-time setup operations:
Setting titles
Instantiating subviews, content arrays
Anything else related to the infrastructure of the view in question
After that, use viewWillAppear: to do anything related to refreshing data. You shouldn't have to call any of the viewDid/viewWill methods manually – that's handled by the innards of UIView. viewDidLoad won't fire after you dismiss a modal view controller because, more than likely, the view never unloaded. viewDidLoad fires fine when you're navigating the a view controller stack since the new views need memory, requiring other views to unload, then be reloaded when they reappear.

How to re-load UIView after memory unload?

My main view controller (representing the Main Menu in my app) has a simple UIView with a few sub views. I am using a modal-type design pattern and switch to multiple other view controllers before finally returning to the main menu. The problem is, in my other view controllers (not the main menu one), I often load data-heavy images and the like which sometimes causes the main menu (which is not currently on-screen) to unload its view to in response to memory warnings. The problem is, when I ultimately switch back to my main menu, the screen is all black and all but a few UILabels have been dispensed of. At this point, I would like to re-load my view and start fresh. But in the documentation, it says that you should never call -loadView directly. How can I re-load my view?
In this situation, check the isViewLoaded property — it should be returning NO. If the view has been unloaded correctly, isViewLoaded will return NO and calling view on your view controller will automatically load in the view again.
Check your custom view unloading code — you should be removing everything from the view hierarchy ([[self view] removeFromSuperview]) that belongs to you.
If you haven't got any unloading code, make sure you're not over-retaining some of your views, which will cause problems when unloading.