0

我的第一个视图显示图像和操作指示器,而 Web 服务器和数据库功能在该背景下运行。我希望应用程序在功能完成后转到我的选项卡视图。我该怎么做呢?

这是视图的样子。 第一和第二视图

我试过的:

TabBarViewController *tab = [[TabBarViewController alloc]init];
[self presentViewController:tab animated:NO completion:nil];

[self performSegueWithIdentifier:@"first" sender:self];

请你能帮助我理解如何做到这一点。我花了很多时间在谷歌上搜索这个问题,但不知道该怎么做。

谢谢

编辑:添加代码

4

5 回答 5

2

由于您正在下载数据,您可以在下载请求完成时接到电话,如下面的方法

- (void)requestFinished:(ASIHTTPRequest *)request

在这种方法中,您可以很好地展示您的TabBarViewController.

于 2012-10-22T11:06:44.763 回答
1

您可以为此声明一个单独的方法。

当你的函数完成时调用下面的方法。

[self performSelector:@selector(gotonext:) withObject:nil afterDelay:4.0];

-(void)gotonext;
{
TabBarViewController *tab = [[TabBarViewController alloc]init];
[self presentViewController:tab animated:NO completion:nil];
}
于 2012-10-22T10:58:12.907 回答
1

嗯...如果你把

 TabBarViewController *tab = [[TabBarViewController alloc]init];
 [self presentViewController:tab animated:NO completion:nil];

dispatch_async(dispatch_get_main_queue(), ^{
        //stop the loader once the database stuff has finished and get rid of the text
        [[self firstLoader]stopAnimating];
        self.downloadingLabel.text = @"";

        });

更新:如果你想做这个同步

dispatch_sync(a_queue, ^{ wait_for_me(); }); 然后展示你的 VC。

于 2012-10-22T11:03:59.367 回答
1

您可以使用 GCD 来实现这一点。

例如,firstViewController在您触发下载的地方,您可以执行以下操作:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ [model downloadData]; dispatch_sync(dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"YourSegueIdentifier" sender:self]; }); });

我假设您的downloadData方法是同步的,如果不是,您可以在模型中使用通知。检索到数据后,您可以postNamedNotification从中注册通知,并在收到通知后NSNotificationCenter致电firstViewControllerperformSegueWithIdentifier

于 2012-10-22T11:04:00.990 回答
1

在开始时拍摄一张 splashView 图像,如下所示...

    @interface AppDelegate : UIResponder <UIApplicationDelegate>{
        UIImageView *splashView;
    }
    @property (nonatomic, retain) UIImageView *splashView;
    @end

在 AppDelegate.m 文件中...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        splashView = [[UIImageView alloc] initWithFrame:iphoneFrame];
        splashView.image = [UIImage imageNamed:@"Default"];
        [self.window addSubview:splashView];
        [self.window makeKeyAndVisible];

        UIViewController *viewController1 = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];
                UINavigationController *navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
                navviewController1.title = @"FirstTitle";
        //        navviewController1.navigationBarHidden=YES;

        UIViewController *viewController2 = [[[yourviewController2 alloc] initWithNibName:@"yourviewController2" bundle:nil] autorelease];
                UINavigationController *navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
        //        navviewController2.navigationBarHidden=YES;
                navviewController2.title = @"SecondTitle";

        UIViewController *viewController3 = [[[yourviewController3 alloc] initWithNibName:@"yourviewController2" bundle:nil] autorelease];
                UINavigationController *navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
        //        navviewController3.navigationBarHidden=YES;
                navviewController3.title = @"ThirdTitle";

               //..... and so on depend on your requirement 

        self.tabBarController = [[[UITabBarController alloc] init] autorelease];
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2 , navviewController3 ,nil];
        [self performSelector:@selector(loadViewIphone) withObject:nil afterDelay:2.0];//**add this line at your all data are loading completed**
    } 
    else 
    {
        splashView = [[UIImageView alloc] initWithFrame:ipadFrame];
        splashView.image = [UIImage imageNamed:@"Default_iPad"];
        [self.window addSubview:splashView];
        [self.window makeKeyAndVisible];
        [self performSelector:@selector(loadViewIpad) withObject:nil afterDelay:2.0];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

-(void)loadViewIphone 
{
    [splashView removeFromSuperview];

    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];   

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFromBottom];
    [animation setDuration:1.0];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:@"transitionViewAnimation"];


    [self.window makeKeyAndVisible];
}

我希望这可以帮助你...

于 2012-10-22T11:09:31.670 回答