gpt4 book ai didi

iphone - 转到下一页时的 Objective-c :"Please wait"消息

转载 作者:行者123 更新时间:2023-11-28 23:03:21 25 4
gpt4 key购买 nike

我正在开发一个有多个 View Controller 的应用程序。第一个是“MainMenu”,第二个是“Page1”。

我想在转到下一页时显示一个提示“请稍候...”。我下面的代码正在运行,但在加载“page1”后出现警报。我希望它在用户按下“MainMenu”页面上的按钮时出现。

你有什么建议来实现这个目标吗?

提前致谢。

AppDelegate.m

-(void)showAlert{
altpleasewait = [[UIAlertView alloc] initWithTitle:@"Please Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];

[altpleasewait show];

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

indicator.center = CGPointMake(altpleasewait.bounds.size.width / 2, altpleasewait.bounds.size.height - 50);
[indicator startAnimating];
[altpleasewait addSubview:indicator];
}


-(void)waitASecond{
[self performSelector:@selector(dismissAlert) withObject:self afterDelay:0.8];

}
-(void)dismissAlert{

[altpleasewait dismissWithClickedButtonIndex:0 animated:YES];

}

主菜单.m

-(void)gotoNextPage{

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[appDelegate showAlert];
page1 = [self.storyboard instantiateViewControllerWithIdentifier:@"Page1"];
[self presentModalViewController:page1 animated:NO];

}

Page1.m

AppDelegate  *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

-------------some methods--------------

[appDelegate waitASecond];

最佳答案

这只是一个建议。我会做以下事情。

  1. -viewDidAppear 中的 Page1.m 中,我会调用警报 View 弹出。这发生在主线程上。所以我不会阻止 UI 的显示或响应。

  2. 我会移动所有与加载 Page1 内容相关的方法,例如要从 URL 读取的文本,放入 block 中,并使用 GCD,以便它们在后台发生,而不是阻塞主线程。

一旦加载完成...

  1. 我会接受它们、更新 UI 并关闭警报 View 。

这是一个简单的教程,可能会给你一个想法。 http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

关于iphone - 转到下一页时的 Objective-c :"Please wait"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9685401/

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