I want to load some data when a button is pressed and show a "loading view" as a subview of my current view while it's loading.
So I want to start loading only after the subview did appear. If not my UI gets stuck without a notice (and the subview only shows after the loading is done).
Is there a way to use something like viewDidAppear
for subviews?
Doing the work right after the addSubview:
like this doesn't work:
- (void)doSomeWorkAndShowLoadingView
{
UIView *loadingView = [[[UIView alloc] initWithFrame:self.view.frame] autorelease];
loadingView.backgroundColor = [UIColor redColor];
[self.view addSubview:loadingView];
[self doSomeWork];
[loadingView removeFromSuperview];
}
- (void)doSomeWork
{
sleep(5);
}
(I don't want to do the loading on a new thread, because is's CoreData i'm working on, which is't thread safe).
Thank You!