Reputation: 1087
I am programing under cocoatouch, using x-code.
I add lots UIImageViews in a ViewDidLoad function by [self.view addSubview:test];
.
and if the information on web is changed, the UIImageViews on the UI should be replaced by other ones(remove the original ones and add new ones). is there any typical way to do it?
How to redraw the view? how to remove the UIImageViews that is already loaded by addSubView Method.
Many thanks!
Upvotes: 0
Views: 985
Reputation: 5297
According to Apple's UIView
documentation, you should use setNeedsDisplay.
Upvotes: 1
Reputation: 8515
Store your UIImageView
s in an array. This way, you can easily access them later to remove them from your view.
In MyViewController.h:
@interface ResultsViewController {
NSMutableArray *myImageViews;
}
In MyViewController.m:
- (void)viewDidLoad {
// Initialize image views
UIImageView *imageView = ...
[self.view addSubview:imageView];
[myImageViews addObject:imageView];
}
// Some action is called
- (void)somethingHappens {
// Remove imageViews
for (UIImageView *imageView in myImageViews) {
[imageView removeFromSuperView];
}
// Empty myImageViews array
[myImageViews removeAllObjects];
// Create new imageViews
UIImageView *imageView = ...
[myImageViews addObject:imageView];
}
Upvotes: 0