iPhone/Objective C: Re-using a view?

Soldato
Joined
18 Oct 2002
Posts
15,177
Location
The land of milk & beans
Hey all.

I've knocked up a basic iPhone app which has a UIViewController and 2 UIViews. You can switch from View1 to View2 and back all day long.

The problem though, is that this app is basically a quiz, so View2 is a layout for asking a question, so if the quiz is 10 questions long (it can be a dynamic number of questions, as set in the app settings), I need to repeatedly show View2 over and over 10 times, each time changing the questions and answer (as read from a global NSArray) on the viewDidLoad event.

Still with me?

I'm cool with the pulling out of info from the array, it's just that I can't figure out how to show a new instance of View2, when a previous instance of it is currently visible?

There are lots of tutorials about how to swap between views, but not create and replace on the fly.

Can anyone help?
 
Soldato
Joined
13 Jan 2003
Posts
23,627
Yes.

You don't need to create a new instance, you could reuse it and reprogram the information. It would also be quicker as the view doesn't need to take CPU time or memory initialising etc.

What fields are you using in your view?
 
Associate
Joined
15 Oct 2009
Posts
579
exactly what nickk says.

I can't really see any reason why you would ever want to load a new instance of the same view each time when you can just change the properties of the existing view.
 
Back
Top Bottom