Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 目标-c:“;请稍等;转到下一页时的消息_Iphone_Objective C_Ios_Xcode_Ios5 - Fatal编程技术网

Iphone 目标-c:“;请稍等;转到下一页时的消息

Iphone 目标-c:“;请稍等;转到下一页时的消息,iphone,objective-c,ios,xcode,ios5,Iphone,Objective C,Ios,Xcode,Ios5,我正在开发一个应用程序,它有几个ViewController。第一个是“主菜单”,第二个是“第1页” 我想在进入下一页时显示一个警告,上面写着“请稍候…”。我下面的代码正在工作,但在加载“page1”后会出现警报。我希望它出现时,用户按下“主菜单”页面上的按钮 你对实现这一目标有什么建议吗 提前谢谢 AppDelegate.m -(void)showAlert{ altpleasewait = [[UIAlertView alloc] initWithTitle:@"Please Wait...

我正在开发一个应用程序,它有几个ViewController。第一个是“主菜单”,第二个是“第1页”

我想在进入下一页时显示一个警告,上面写着“请稍候…”。我下面的代码正在工作,但在加载“page1”后会出现警报。我希望它出现时,用户按下“主菜单”页面上的按钮

你对实现这一目标有什么建议吗

提前谢谢

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];

}
主菜单

-(void)gotoNextPage{

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

}
第1.m页

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

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

 [appDelegate waitASecond];   

你能做的就是把警报放在iAction中。检查他们何时解除警报,然后更改视图。或者使用NSTimer,为该计时器指定一个选择器,并实现该选择器以更改视图。

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

  • -viewdide出现的Page1.m中,我会调用警报视图弹出。这发生在主线程上。所以,我并没有阻止用户界面的显示或响应

  • 我会将与加载
    Page1
    内容相关的所有方法(例如,从URL读取的文本)移动到块中,并使用GCD,以便它们发生在后台,而不会阻塞主线程

  • 一旦加载完成

  • 我会接受它们,更新UI,然后关闭警报视图
  • 这里有一个简单的教程,可以给你一个想法。

    你应该试试MBProgressHUD:我同意,效果很好哇,不错。我稍后会试试这个。