How to properly download and redisplay new images/data after UIApplicationDidBecomeActiveNotification
I have a UIViewController that first sets up the view and initializes some HTTPRe开发者_JS百科quests in the -(void)viewDidLoad
and in the callbacks for the HTTPrequests, that is where a bunch of UIImageViews and UILabels and such are dynamically placed into the UIView (they are created and released immediately after the addSubview
).
What I want is for my ViewController to "refresh" with updated images/text when the user presses the home button and opens the app again. I started with
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
And the test method works fine, but I'm stuck on the best way to show the new data.
I thought of adding tags to each and every object that could change, and then altering it like that but that seems like a management nightmare. I read about [self.view setNeedsDisplay]
but I don't think this can work in my situation
setNeedsDisplay will refresh a UIView that is already present. If you have a visible UIImageView, change the image it contains, then call [theImageView setNeedsDisplay] it will do what you want.
Do you really need to programmatically create a bunch of new UIImageViews all the time, or would it work to have some there permanently, while changing the images they display?
If you really do need to remove the UIImageViews and place new ones in your parent view, also add them to a container like an NSMutableArray or an NSSet. Then you can iterate through your container of image views, detach them from their parent views, remove them from the container then release them.
精彩评论