【发布时间】:2017-11-10 22:49:49
【问题描述】:
我在UIViewController 中使用UITableViewController 的视图,如下所示:
UITableViewController *tvc = [[UITableViewController alloc] init];
[self.view addSubview:tvc.view];
现在,在这个UITableViewController 中,我希望能够在必要时提供一个SFSafariViewController。我写了下面的代码:
if (showLink) {
SFSafariViewController *sfsvc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.google.com"]];
[self.presentingViewController.navigationController pushViewController:sfsvc animated:YES];
}
每当我运行此程序时,我都会在控制台中收到以下错误,但什么也没有发生:
[Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFSafariViewController: 0x7f8aef82a600>)
有什么办法可以解决这个问题吗?
【问题讨论】:
-
你为什么不直接使用
UITableView而不是破解UITableViewController?你的问题是你的 safari 视图控制器是一个局部变量,一旦这个函数退出它就会被释放,大概是因为没有任何东西保留你的 tableviewcontroller
标签: ios objective-c uiviewcontroller uinavigationcontroller