【问题标题】:iOS switch back to background UIViewControlleriOS 切换回后台 UIViewController
【发布时间】:2014-03-29 20:00:02
【问题描述】:

我正在寻找一种在当前 UIViewController 上呈现模式视图的方法,以基本上显示 UIActivityIndi​​cator 并强制用户在加载数据时等待。

在 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


    【解决方案1】:

    试试:

    [self dismissViewControllerAnimated:YES completion:nil];
    

    事实上,我不确定用动画 gif 展示新控制器是否是个好主意。

    最好的选择是 (imo) show UIActivityIndicator + place a view on top on all other views to prevent user from clicking anything

    【讨论】:

    • 嗯,这个 gif 是一个 UIActivityIndi​​cator。我将编辑我的问题来描述这一点。此外,这非常有效。我会尽快接受答复。
    【解决方案2】:

    您必须先[self dismissViewControllerAnimated:YES completion:nil]

    检查Apple Documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-07
      • 2014-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      • 2017-08-06
      • 2012-04-17
      相关资源
      最近更新 更多