iOS 切换回后台 UIViewController

标签 ios iphone objective-c uiviewcontroller storyboard

我正在寻找一种方法来在我当前的 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];
}

效果很好,但是加载 View 应该完成后我如何返回到背景 View ?

需要一个 stopLoading 方法返回到原始 View :

// stop loading
-(void) stopLoading
{
    // code here
}

如果我在呈现加载 View 后尝试呈现一个新 View ,如下所示:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *view = [storyBoard instantiateViewControllerWithIdentifier:@"loadingView"];
[self presentViewController:view animated:YES completion:nil];

调试器给出警告:

尝试在 ViewController: 0x8ab23c0 上呈现 PropertyPickerViewController: 0x8af6010,它已经在呈现 LoadingViewController: 0x8acf530

最佳答案

尝试:

[self dismissViewControllerAnimated:YES completion:nil];

事实上,我不确定用动画 gif 呈现新 Controller 是否是个好主意。

最好的选择是 (imo) show UIActivityIndi​​cator + 在所有其他 View 之上放置一个 View 以防止用户单击任何内容

关于iOS 切换回后台 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22050744/

相关文章:

ios - 如何使用 Instagram API 获取我的关注者的关注者列表

ios - 使用 NSURL 运行 swift 代码时出错 EXC_BAD_INSTRUCTION

应用程序未运行时的 iOS 可达性

iphone - 使用自动调整 subview 动画 UIView 帧大小变化

objective-c - 如何创建符合 Swift 和 Objective-C 之间共享协议(protocol)的类方法?

iphone - 显示按日期对核心数据进行排序

javascript - 如何从 Safari 和 native 应用获取/读取和匹配 iOS 设备属性

iphone - ICU 是 iOS 上的私有(private)框架吗?

Ios uialertcontroller uiimagepicker 忽略 : app crash

php - iPhone POST 到 PHP 失败