Question

I have RootViewController where I create my MainViewDownload instance and call method of that instance.

MainViewDownload *download = [[MainViewDownload alloc] init];
[download loadMainViewImages];

How can I know when loadMainViewImages is finished ? I only call loadMainViewImages from RootViewController but loadMainViewImages calls another method inside MainViewDownload class (lets say method2), and that method2 calls again method3. So, is there a way to know when loadMainViewImages is finished (actually when method3 is finished since its last called).

Was it helpful?

Solution

If you're not multithreading, i.e. starting a method that runs on a separate thread from loadMainViewImages, then the methods will be executed sequentially. So once the loadMainViewImages returns you can be sure everything "in it" was executed. This is how methods work.

EDIT for better formatting of the comments:

MainViewDownload.h

@protocol MainViewDownloadDelegate;

@interface MainViewDownload
@property (nonatomic, weak) NSObject<MainViewDownloadDelegate> *delegate;
@end

@protocol MainViewDownloadDelegate
- (void)downloadDidFinish:(MainViewDownload *)download;
@end

MainViewDownload.m

@implementation MainViewDownload

- (void)someMethodThatDownloadsStuff_OrIsCalledAfterTheDownload {
    ...
    if ([self.delegate respondsToSelector:@selector(downloadDidFinish:)]) {
        [self.delegate downloadDidFinish:self];
    }
}

@end

RootViewController.h

@interface RootViewController <MainViewDownloadDelegate>
...
@end

RootViewController.m

@implementation
...
- (void)downloadDidFinish:(MainViewDownload *)download {
    // hide the download view here.
}
@end

Make sure to set the delegate of the download view to the root view controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top