gpt4 book ai didi

ios - 在同一方法中处理和运行多个 ViewController

转载 作者:行者123 更新时间:2023-11-29 02:46:49 26 4
gpt4 key购买 nike

我有一个带有按钮初始化的 MainViewController。在按钮上单击图片开始动画,然后我创建一个不同 ViewController 的新实例,该实例运行 Web 请求并提取一些信息并将其推到前面。我希望图像在中间 View Controller 运行时具有动画效果。最后,一旦 MiddleViewController 完成,在相同的按钮方法中我切换到第三个 ViewController。正如预期的那样,我收到以下错误:

    Warning: Attempt to present <ThirdViewController: 0x962b470> on <MainViewController: 0x986c200> while a presentation is in progress!
Unbalanced calls to begin/end appearance transitions

我该如何解决这个问题?我不希望删除中间的 ViewController 并将其代码集成到 MainViewController 中。

-(void)singleTapping:(UIGestureRecognizer *)recognizer
{

UIImage *rot1 = [UIImage imageNamed:@"pic1.png"];
UIImage *rot2 = [UIImage imageNamed:@"pic2.png"];
UIImage *rot3 = [UIImage imageNamed:@"pic3.png"];
UIImage *rot4 = [UIImage imageNamed:@"pic4.png"];

self.scanclickedimage.animationImages = [[NSArray alloc] initWithObjects:rot1, rot2, rot3, rot4, nil];
self.scanclickedimage.animationDuration = 0.6f;
self.scanclickedimage.animationRepeatCount = HUGE_VALF;

[self.scanclickedimage startAnimating];


if (nextString == NULL || [nextString isEqualToString:@""]) {

NSLog(@"Initializing MiddleViewController");
MiddleViewController * middleViewController = [[MiddleViewController alloc] init];
middleViewController.delegate = self;

[self presentViewController:middleViewController animated:YES completion:nil];



} else {
ProductWebRequest *request = [[ProductWebRequest alloc] init];
[request sendWebRequest:nextString];
}






NSString * storyboardName = @"MainStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"ThirdViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:nil];




}

最佳答案

有时,当您同时(或非常快)呈现/推送超过 2 个 View Controller 时,并且“动画”选项设置为"is"时,会出现此错误。

尝试像这样将动画设置为“NO”:

[self presentViewController:middleViewController animated:NO completion:nil];

或者做这样的事情:

[self presentViewController:middleViewController animated:YES completion:{
[self presentViewController:vc animated:YES completion:nil];
}];

您必须更新代码才能执行此操作。尝试像这样将所有内容放在单独的方法中:

-(void)singleTapping:(UIGestureRecognizer *)recognizer
{

UIImage *rot1 = [UIImage imageNamed:@"pic1.png"];
UIImage *rot2 = [UIImage imageNamed:@"pic2.png"];
UIImage *rot3 = [UIImage imageNamed:@"pic3.png"];
UIImage *rot4 = [UIImage imageNamed:@"pic4.png"];

self.scanclickedimage.animationImages = [[NSArray alloc] initWithObjects:rot1, rot2, rot3, rot4, nil];
self.scanclickedimage.animationDuration = 0.6f;
self.scanclickedimage.animationRepeatCount = HUGE_VALF;

[self.scanclickedimage startAnimating];


if (nextString == NULL || [nextString isEqualToString:@""]) {

NSLog(@"Initializing MiddleViewController");
MiddleViewController * middleViewController = [[MiddleViewController alloc] init];
middleViewController.delegate = self;

[self presentViewController:middleViewController animated:YES completion:^{
[self launchTest];
}];

} else {
ProductWebRequest *request = [[ProductWebRequest alloc] init];
[request sendWebRequest:nextString];
[self launchTest];

}
}

- (void)launchTest {

NSString * storyboardName = @"MainStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"ThirdViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:nil];
}

关于ios - 在同一方法中处理和运行多个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25011975/

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