سؤال

Now I'm using this code, with a little modification:

if (self._photoPath && !self._photo) {
    dispatch_queue_t bg_thread = dispatch_queue_create("com.yourcompany.bg_thread", NULL);
    dispatch_queue_t main_queue = dispatch_get_main_queue();
    dispatch_async(bg_thread,^{
        NSData *data = [NSData dataWithContentsOfFile:self._photoPath];
        if(data != nil) {
            dispatch_async(main_queue,^{ 
                self._photo = [UIImage imageWithData:data];
                [self.photoButton setImage:[UIImage imageNamed:@"photoButton.png"] forState:UIControlStateNormal];
            });
        }
    });

}

As you can see, in fact after I get that photo I want set it immediately to my "photoButton",

but now, UI got smoothed, but my photoButton's appearance is always black...

What should I do next?

Thanks for your patience.

_______________Updated________

I have 2 viewControllers, A and B.

A is the root viewController, and B is A's child viewController.

In B, there is a button for calling the camera to take a photo.

After user toke a photo, the photo's apperance becomes that photo.

When I push a new B (with no photo) from A,

things goes smoothly.

But when there is an old B with a photo in it.

the animation gets a little stucked, since the following code I guess:

- (void)viewWillAppear:(BOOL) animated {
if (self._photoPath && !self._photo) {
        NSData *data = [NSData dataWithContentsOfFile:self._photoPath];
        if(data != nil)
            self._photo = [UIImage imageWithData:data];
}
[super viewWillApear];

}

But I do need to get that photo before the view is displayed since I need to set that photo to my photoButton's background.

So, is there a way to avoid stucking the view's animation? Cause it really result in bad user experience.

Thanks a lot!

هل كانت مفيدة؟

المحلول

I found the answer.

Just add a line of code to refresh the button.

For me, it is

[self.photoButton setImage:[UIImage imageNamed:@"photoButton.png"] forState:UIControlStateNormal];
NSUInteger p[2] = {1,4};
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:
                              [NSIndexPath indexPathWithIndexes:p length:2]] 
                      withRowAnimation:UITableViewRowAnimationNone];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top