在 iOS 9 中不鼓励在分离的视图控制器上显示视图控制器?
Posted
技术标签:
【中文标题】在 iOS 9 中不鼓励在分离的视图控制器上显示视图控制器?【英文标题】:Presenting view controllers on detached view controllers is discouraged in iOS 9? 【发布时间】:2016-04-20 07:23:10 【问题描述】:在我的应用程序中,当我从 tableview 页脚部分移动到另一个视图控制器时,它运行良好,但移动应用程序后会崩溃。之后我收到此错误。
这是我的代码:
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
if(tableView == educateTbl) //here you can make a decision
float footerWidth = 150.0f;
float padding = 10.0f;
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, footerWidth, 50.0)];
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *addEdu = [[UIButton alloc]initWithFrame:CGRectMake(padding, 0, footerWidth - 2.0f * padding, 44.0f)];
addEdu.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
addEdu.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
addEdu.backgroundColor = [UIColor colorWithRed:23/255.0 green:186/255.0 blue:239/255.0 alpha:1.0];
[addEdu setTitle:@"Add Education" forState:UIControlStateNormal];
[addEdu addTarget:self action:@selector(addEducation:) forControlEvents:UIControlEventTouchUpInside];
[addEdu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];//set the color this is may be different for ios 7
addEdu.frame=CGRectMake(0, 0, 200, 30); //set some large width to ur title
[footerView addSubview:addEdu];
return footerView;
return nil;
- (void)addEducation:(id)sender
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AddEducationViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"AddEducationVC"];
[self presentViewController:ivc animated:YES completion:nil];
【问题讨论】:
发布错误,即将发生什么错误 你必须用强指针保持ivc
。
@AayushKatiyar。查看我更新的问题。
你在 addEducationViewController.h 和 .m 文件中写了什么
Warning :-Presenting view controllers on detached view controllers is discouraged的可能重复
【参考方案1】:
[self presentViewController:ivc animated:YES completion:nil];
尝试改变:
[self.view.window.rootViewController presentViewController:deleAlert animated:YES completion:nil];
【讨论】:
以上是关于在 iOS 9 中不鼓励在分离的视图控制器上显示视图控制器?的主要内容,如果未能解决你的问题,请参考以下文章
在 ios swift 中导航到其他屏幕时,不鼓励在分离的视图控制器上显示视图控制器
popViewController:animated: 在 iOS 9 中不工作
Swift 3 - UIPageViewController - 不鼓励在分离的视图控制器上呈现视图控制器