sxingfeng
sxingfeng

Reputation: 1087

How to redraw a view in coco-touch iOS?

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

Answers (2)

folex
folex

Reputation: 5297

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

Upvotes: 1

mopsled
mopsled

Reputation: 8515

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];
}

Upvotes: 0

Related Questions