开发者

How redraw UIView

开发者 https://www.devze.com 2023-03-23 03:15 出处:网络
In loadDidLoad controller call method with thread, like that: - (void)viewDidLoad { [super viewDidLoad];

In loadDidLoad controller call method with thread, like that:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadImages) object:nil];
    [self.operationQueue addOperation:operation];
    [operation release]; 
}

loadImages method downloading image and show it:

- (void) loadImages {

    @synchronized (self) {
        // download image...
        // ...
        // and next:
        UIImageView *imageView = [imageViews objectAtIndex:currentImageIndex];
        [imageView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
        [imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageWithData:imageData] waitUntilDone:YES];
    }
         //...
}

that work if show view first time, next time i must rotate iphone to show images. why view doesn't redraw?


i tried this code according to advices:

// imageButton is a UIView with button, image and label
NSData   *imageData = [[HttpClient sharedInstance] getResourceWithCache:thumbPath];
[imageButton performSelectorOnMainThrea开发者_Go百科d:@selector(setImage:) withObject:[UIImage imageWithData:imageData] waitUntilDone:YES];
[imageButton performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
[imageButton drawRect:imageButton.frame];

but do not work.


your problem is in the line

        [imageView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];

You would need to call setNeedsDisplay in self.view and not on self, as thats a method for UIView and not UIViewController.

Double check this by subclassing your view and putting a break point in drawRect: , as setNeedsDisplay must call drawRect.


I'm assuming that loadDidLoad is a typo, and that you meant viewDidLoad.

The viewDidLoad method is called when the view controller is done loading. It only does this once, unless the app receives a memory warning and the view controller gets unloaded.

If you're retaining the view controller and later showing the same view controller object again, the viewDidLoad method does not get called again.

If you need to perform an action every time the view controller gets pushed onto the view stack, you can use viewWillAppear: or viewDidAppear:.

0

精彩评论

暂无评论...
验证码 换一张
取 消