首页 > 开发 > iOS > 正文

MBProgressHUD加在self.navigationController.view出现的诡异问题

2017-09-08 14:03:58  来源:网友分享

在一台联通3G iPhone4s越狱手机上发现HUD有些情况不显示.我自己的移动越狱手机是好的.
系统都是5.1.1
添加HUD目的是在用户点发送时屏蔽全屏不让点击, 用法如下:
在viewDidLoad中初始化

self.HUD = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0, -420+44, 320, 1000)];//挡住键盘下的绑定范围不让点击    self.HUD.labelText = @"正在加载";    [self.navigationController.view addSubview:self.HUD];    [self.navigationController.view bringSubviewToFront:self.HUD];//这里打印self.navigationController和self.navigationController.view是必然有值的!

之后用户可以有拍照操作

UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;        imagePicker.delegate = self;        [self presentModalViewController:imagePicker animated:YES];

拍照完后竟然发现有时候self.navigationController.view是nil, 导致HUD.superview=nil.
表示非常不解! 本来想用gdb跟踪HUD.superview, 结果说没这个属性..
莫非是打开相机或者在内存警告时系统对navigationController做了些什么事?

我改成加在window上免倒是没重现问题,但是总感觉影响全局. 大家的全屏蒙板一般都加载window上么?
多谢

解决方案

navigationController是继承自UIViewController的.
打开相机之前的页面会收到内存警告而又被相机挡住,所以navigationController应该会调用viewDidUnload释放navigationController.view, 所以我的HUD.superview就为nil了.
做法要么就加到window上,要么就每次显示前都用navigationController.view addSubview