Run ViewDidLoad method on FlipViewController - iphone

I have a few settings in my flipviewcontroller utility application and when I click "Done" I want to be able to refresh the screen on the MainViewController. Is there a way to do this?

#Ravin is correct -- you should use -viewWillAppear rather than -viewDidLoad. -viewDidLoad is for initialization that has to be deferred until after the view is loaded; what you're talking about is an update that should happen whenever the view appears.

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.

How to refresh UIViewController view on click of some buttons

I'm developing an iPhone app, i have a UINavigationControlller in my AppDelegate.i have refresh button on other view.Button have an IBAction method on clicking a button. i am using this code
[AppDelegate.navigationController.topViewController.view setNeedsDisplay];
My problem is how can i refresh my page(reload) on click of these button,setNeedsDisplay method not called view life cycle methods eg. viewDidLoad,viewWillAppear
Am I doing it correct or is there a way of doing what I do?
thanks in Advance.
Instead of reloading the viewController, you should write a method (or two, or more) that refreshes the data you need to.
That will avoid collateral problems while you add functions later.
setNeedsDisplay does not call into view controller life cycle methods like viewDid/Will ... - you are calling setNeedsDisplay on a UIView, not on a UIViewController.
setNeedsDisplay triggers a redraw of the UIView and it's subviews;
put a breakpoint into your view's drawRect: and you will see it is hit when pressing the button.

Back button in UINavigationController

So, I am well aware that when the back button is pressed in classes embedded in UINavigationControllers, the previous view's viewDidAppear() method is called. However, I need the viewDidLoad() method to be called, much like it is with a push segue into a scene. Is there a possible way to do this? Maybe by modifying the method that is called when the back button is pressed? What is the method that is called when the back button is pressed? Thanks.
Firstly viewWillAppear and then viewDidAppear is getting called on push back. And for lazy loading of views, it is preferable to add/operate UI subviews in viewWillAppear, and make them set view to nil in viewDidDisappear for memory management.
viewDidLoad is only called when the view has loaded. There's a difference between views being loaded/unloaded and them appearing/disappearing: a view can disappear without being unloaded. Usually iOS will not unload a view, even if it is hidden/replaced by by another view, unless a low memory situation occurs.
Don't ever call viewDidLoad etc. yourself (except for the super call in subclass overrides).

Reload all subViews of current ViewController

I have a situation where i have to reload all subViews of my current view....I am adding all objects(like buttons, images ...etc) from interface builder.....
And i want to reset these subviews when user click on a button...
i tried [self.view setNeedsDisplay]; but it doesn't works.
Is there any simple way to do this...
Any suggestion?
I am not sure that what happening in your code but i guess
You should add all subview programatically and refresh on button click event,
or write code in viewDidAppear method.
Reloading them sounds like the wrong thing to do. You can easily reset them to their default state programmatically by setting the various properties to your defaults. Once you do that I would probably just create the whole view and subviews programmatically without using IB. I do everything programmatically now and find it easier to maintain my code.
You could come up with a NIB based solution by putting all affected subviews within a parent UIView and load just that parent view from a NIB and then replace the parent UIView only but I don't recommend it. You need to able to set subview properties programmatically in viewDidLoad anyway in case the view controller needs to unload/reload the view based on memory warnings.
May be this is helpful to you.
One way is create on UI method that set default or required value for required controllers. And call it on button event.

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.