【问题标题】:Modal transition - One of the views is seemingly getting deallocated模态转换 - 其中一个视图似乎正在被释放
【发布时间】:2014-03-30 21:05:35
【问题描述】:
在我的应用程序中,我进行了异步搜索。当完成我的 mapViewController 时,将显示位置的引脚。 2 秒后,我将模态转换到 listViewController。我这样设置背景颜色:
self.view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.65];
可以看到它背后的地图。
问题是这样的:listView 出现后不到一秒钟,您可以在背景中看到地图一秒钟,然后它就会消失。我现在可以在后台看到的是应用启动时的 mainViewController。
看起来像这样:
不到一秒后:
任何帮助/解释将不胜感激。
【问题讨论】:
标签:
ios
objective-c
uiviewcontroller
uitableview
presentmodalviewcontroller
【解决方案1】:
您的视图仍然是透明的,但是一旦您的模态控制器位于堆栈的顶部,它后面的视图就会被隐藏。
尝试使用:
yourController.modalPresentationStyle = UIModalPresentationCurrentContext;
[yourController present...];
【解决方案2】:
This code seems to work. I hope it will help.
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
MKMapView *mapView = [MKMapView new];
[self.view addSubview:mapView];
mapView.frame = self.view.bounds;
UIGestureRecognizer *gestureRecognizer = [UITapGestureRecognizer new];
[gestureRecognizer addTarget:self action:@selector(displayTransparentVC)];
[self.view addGestureRecognizer:gestureRecognizer];
}
-(void)displayTransparentVC
{
UIViewController *vc = [TransparentViewController new];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:^{
}];
}