Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload my UIViewController on click of some buttons?

I'm developing an iPhone app, i have a UIViewController class where some coverflow animations are there and according to design i have some 5 buttons on top of my view each button have an IBAction method on clicking a button i need to display different set of coverflow with different data and the count of coverflow also changes from 1 button action to another. My problem is how can i refresh my page(reload) on click of these buttons, as i know calling explicitly viewDidLoad is a very bad idea, so how can i accomplish this? Any help is appreciated in advance thank you.

like image 805
George Avatar asked Oct 11 '11 11:10

George


2 Answers

The easiest way to get a view to re-draw itself is to call [UIView setNeedsDisplay] or by using [UIView setNeedsDisplayInRect]. This method tells the view that it needs to re-draw itself and it's subviews. However you shouldn't always have to call this. There are other methods that can cause views to redraw themselves. For instance if you add or remove a view to the view hierarchy using [UIView addSubview:] or [UIView removeFromSuperview].

These methods cause the system to call your view's drawInRect: method (assuming you overrode it with custom drawing code). If you did not override this method for custom drawing then it should cause your subviews to receive the same message so that they can get a chance to redraw.

Additional information here. Specifically read the section labeled "The View Drawing Cycle".

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

like image 102
Carter Avatar answered Sep 25 '22 02:09

Carter


Why do you want to reload the page?, if it is because you are changing your view and you want it to be redrawn, you can call:

setNeedsDisplay();

But that is often not needed, as whenever a views bounds change that is called automatically for you.

like image 25
Oscar Gomez Avatar answered Sep 23 '22 02:09

Oscar Gomez