gpt4 book ai didi

ios - Objective C 如何在从第一个 VC 移动到第二个时停止无限循环

转载 作者:行者123 更新时间:2023-11-29 00:32:09 25 4
gpt4 key购买 nike

我正在尝试构建启动画面,所以我希望第一个 View Controller 在 3.0 秒后自动移动到第二个 ViwController 我已经尝试了以下方法但是无限循环已经开始我应该做什么,我应该如何在第二个停止 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.
}

enter image description here三秒后查看循环如何工作。

最佳答案

你为什么不使用 NSTimer 类。只需创建一个 10 秒的计时器,当 10 秒过去时计时器将触发该事件,在该事件中您可以移动到另一个 Controller 。创建一个像这样的计时器

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



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

关于ios - Objective C 如何在从第一个 VC 移动到第二个时停止无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41479764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com