iOS SDK - reinitializing UIView with original configuration
I'm a "fresh" iOS developer and trying to resolve an issue as follows -
I'm trying to build a game and I've created a UITabBarController
with 3 UINavigationController
items. One of the items' view - the game session - is modified during running (e.g. labels/buttons appear/disappear etc).
Now, when the game is completed I would like to reload the self view from beginning with the default configuration.
Since [[self view] setNeedsDisplay]
doesn't do it I wonder how this process should be done?
I can build a method that bring all 开发者_StackOverflowthe objects to their default state but I guess this is not the right way to do it.
You'll have to hold on to your default state within your view class. Create a subclass of UIView
and make some method like -resetToDefaultState
where you do what you want. Then just call that method in your view controller. Or put the state resetting logic in your view controller itself, though I would argue it probably the view's concern what "default state" even means.
Then, in that method, just reset variable labels and properties. As a side effect, you can call this method in your view's init
methods so you don't duplicate your default state code.
(By the way, -setNeedsDisplay
has nothing to do with default state or anything. It just marks the view as dirty so that its -drawRect:
method is called on the next main run loop cycle.)
精彩评论