开发者

A function called from different class does not work properly

开发者 https://www.devze.com 2023-02-15 12:31 出处:网络
I have a tabbar iPhone application in which tabbar is the root controller and each of the tabs is launching a separate webview window. Each time user taps one of the tabs I intercept the tap in AppDel

I have a tabbar iPhone application in which tabbar is the root controller and each of the tabs is launching a separate webview window. Each time user taps one of the tabs I intercept the tap in AppDelegate and perform actions, one of which is displaying loading screen (an image in the tabbar view, with display toggled TRUE/FALSE).

My problem is, the loading screen is only displayed when all operations in AppDelegate are finished, which pretty much defeats the purpose of it. My guess is th开发者_StackOverflow社区at I did some fundamental error designing this solution, but being a very inexperienced in iPhone programing I don't know how to fix it.

I'm accessing the function showLoading through iboutlets defined in AppDelegate:

[hv showLoading];

And this is what it does:

- (void) showLoading
{
    loadingView.hidden = FALSE;
    wheelHome.hidden = FALSE;
    [wheelHome startAnimating];
    NSLog(@"showLoad 1");
}

I'm seeing the "showLoad 1" immediately after bar is tapped, but loading image is only displayed when didSelectViewController exits.

My question - how can I make loading screen appear from AppDelegate OR is there a better way to display loading screen?


The problem is, that the UI is only updated when the event handling code returns to the run loop. You have two options:

  1. Prepare for your long-running task (setup the UI) and then start the task by [myDownloader persormSelector:@selector(download) withObject:nil afterDelay:0];. The benefit of using performSelector:withObject:afterDelay: is that your code returns to the run loop, gets time to update the UI, and then immediately starts the task.
  2. Design your long running tasks (downloading, ...) so that they perform in the background.


First of all, your tabbar should be controller by a UITabBarController and not the app delegate. See the Xcode TabBar template for implementation details.

Secondly, it sounds like you want an Application Startup Image. That is a static image that works like a splash screen if you app takes a little while to startup.

0

精彩评论

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

关注公众号