目标C如何在从第一个VC移至第二个VC时停止无限循环 [英] Objective C how to stop infinte loop while moving from first VC to 2nd

查看:127
本文介绍了目标C如何在从第一个VC移至第二个VC时停止无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建启动画面,因此我希望第一视图控制器在3.0秒后自动移至第二ViwController,我尝试了以下方法,但无限循环已开始,我该怎么办,我该如何停下来查看控制器.

I am trying to build a splash screen so I want the 1st View Controller to move to 2nd ViwController automatically after 3.0 sec I have tried the below method but an infinite loop has started what should i do ,how should I stop on second view controller.

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"%p", self);
    NSLog(@"1st Controller");

    [self.navigationController setNavigationBarHidden:YES animated:YES];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{


        [self loadingNextView];
      });

}

    - (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
- (void)loadingNextView{

    LoginViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [self.navigationController pushViewController:viewController animated:true];
}
//LoginViewController.h
@interface LoginViewController : ViewController

@end
//LoginViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"2nd View Controller");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

三秒钟后,看看循环是如何工作的.

see after three seconds how the loop is working .

推荐答案

为什么不使用NSTimer类.如果经过10秒钟的计时器将触发该事件,则只需创建一个10秒钟的计时器,在这种情况下,您可以移至另一个controller.创建一个这样的计时器

Why don't you use NSTimer class. Simply create a timer for 10 seconds when 10 seconds passed timer will trigger the event and in that event you can move to another controller. Create a timer like this

[NSTimer scheduledTimerWithTimeInterval:10.0
        target:self
        selector:@selector(targetMethod:)
        userInfo:nil
        repeats:NO];



    - (void)targetMethod:(NSTimer*)timer {
        [self loadingNextView];
    }

这篇关于目标C如何在从第一个VC移至第二个VC时停止无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆