【发布时间】:2014-03-29 20:00:02
【问题描述】:
我正在寻找一种在当前 UIViewController 上呈现模式视图的方法,以基本上显示 UIActivityIndicator 并强制用户在加载数据时等待。
在 BaseViewController.m(我所有 UIViewController 的基类)中:
// show loading view
-(void) showLoading
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
LoadingViewController *loading = [storyBoard instantiateViewControllerWithIdentifier:@"loadingView"];
loading.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.7];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:loading animated:NO completion:nil];
}
这很好用,但是在加载视图完成后如何返回背景视图?
需要一个 stopLoading 方法才能回到原来的视图:
// stop loading
-(void) stopLoading
{
// code here
}
如果我在呈现加载视图后尝试呈现新视图,如下所示:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *view = [storyBoard instantiateViewControllerWithIdentifier:@"loadingView"];
[self presentViewController:view animated:YES completion:nil];
调试器给出警告:
Attempt to present PropertyPickerViewController: 0x8af6010 on ViewController: 0x8ab23c0 which is already presenting LoadingViewController: 0x8acf530.
【问题讨论】:
标签: ios iphone objective-c uiviewcontroller storyboard