0

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!

sxingfeng
  • 971
  • 4
  • 15
  • 32

2 Answers2

1

According to Apple's UIView documentation, you should use setNeedsDisplay.

folex
  • 5,122
  • 1
  • 28
  • 48
0

Store your UIImageViews 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];
}
mopsled
  • 8,445
  • 1
  • 38
  • 40