Rebooting a UIView when a bookmark icon is clicked?

I have an application using UITabBarController, and there are navigation controllers inside each tab. I would like one of the views to reboot after the action occurs in another view, so that when the user returns to this view, it will be updated. Is it possible?

Thanks a bunch!

+3
source share
2 answers

The easiest way to do this is to add viewWillAppear download code: instead viewDidLoad. While it viewDidLoadcan only be called once when your view is initialized, it viewWillAppear:is called at any time when your view controller will be displayed, whether on the tab bar, in the navigation controller, etc., which gives you a good hook for implementation download and layout features.

+8
source

Thank. which worked great. For anyone reading this, my code. It works, but we warn you, I'm new to iOS and objective-C, so I caution emptor.

- (void)viewWillAppear:(BOOL) animated
{
    NSURL *imageURL = [NSURL URLWithString:@"http://www.domain.com/image.jpg"];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
        dispatch_async(dispatch_get_main_queue(), ^{
            // Update the UI
            self.img.image = [UIImage imageWithData:imageData];
        });
    });
}
0
source

Source: https://habr.com/ru/post/1781301/


All Articles