How to refresh UIViewController view on click of some buttons - iphone

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.

Related

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).

Is it possible to call a UIEvent between viewWillAppear and viewDidAppear?

Is it possible to handle UIEvents between viewWillAppear and viewWillDisappear?
For example:
Let's say I have a view controller with a UITableView.
When pressing a cell I push a another view controller to the navigation controller (And display it of course).
Is it possible that after the viewWillAppear event of the pushed view (And before the viewDidAppear) I can still press one of the cells in the UITableView?
I am asking this because I am seeing this in the logs of my application and I Never thought that such a thing could be possible..
What do you guys(Or girls) think?
Thanks!
I have one idea may this work,
you use performSelector in viewWillAppear with 0.01 or another time with Delay Parameter and call your method here,
hope,this help you.
:)

how to refresh UX data on a ViewController when its TabBarItem gets tapped?

In the view controller that has a UITabBarItem, i realized that viewDidLoad() method only gets called the first time when the tab bar item is clicked. So I dont know how to bring up the dynamic graphics when it's clicked the 2nd time. Can some guru help me on this? thanks in advance.
Should I conform to some kind of delegates or should i do it within didSelectViewController method on the root controller of all the tab bars? If i do the later one, it just seems to be weird since i think the controller that has the corresponding tab bar item should render itself instead of doing the rendering on root controller..
You want to put any code that should run every time the view controller appears in viewWillAppear: instead of viewDidLoad. viewDidLoad is designed for code that should run when the view backed by your UIViewController is created (and then possibly re-created after being thrown away during low-memory situations).
Actually i resolved this by using the parameter passed into the callback didSelectViewController(param).

How to tell when a subView is removed a UIView

Basically i wanted to implement a popup UIView so i followed what was posted here
POP-UP UIView "IMDB App" style
This works very well. However i have one query. My main view is a tableView. so when a view is popped up i disable scrolling in the table. Now when the popup subView is removed, i need to re-enable scrolling. How do i achieve that? i can't use willRemoveFromSuperview because the popup view is loading a different NIB altogether.
Should i use Notifications?
hope i was clear with explaining the scenario.
Thanks in advance!
Feloneous Cat has the correct answer. This is the perfect use a #protocol in your popup view along with a registered delegate. Something is triggering that popup view to close. Whatever that trigger is, call the protocol and the delegate can handle the situation as needed.
Furthermore, when protocols are used correctly, your code becomes very reusable within a project as well as in other projects.
What you could do is subclass UIView and override removeFromSuperview to send a notification. I don't think there's ever a case where a view gets removed without using the removeFromSuperview method.

Run ViewDidLoad method on FlipViewController

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.