如何在不使用按钮的情况下移动到另一个视图

时间:2012-10-22 10:50:38

标签: iphone objective-c ios xcode ios6

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

这是观点的样子。 First and Second views

我尝试过:

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

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

请帮助我理解如何做到这一点。我花了很多时间在Google上搜索这个问题并且无法解决这个问题。

谢谢

编辑:已添加Code

5 个答案:

答案 0 :(得分:2)

由于您正在下载数据,因此您可以在下载请求完成时接听电话 喜欢下面的方法

- (void)requestFinished:(ASIHTTPRequest *)request

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

答案 1 :(得分:1)

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

当您的功能完成时,请调用以下方法。

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

-(void)gotonext;
{
TabBarViewController *tab = [[TabBarViewController alloc]init];
[self presentViewController:tab animated:NO completion:nil];
}

答案 2 :(得分: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。

答案 3 :(得分: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 NSNotificationCenterfirstViewController注册通知,收到通知后,您可以致电performSegueWithIdentifier

答案 4 :(得分: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];
}

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