2017-11-10 192 views
0

我使用的是UITableViewController的在UIViewController认为目前的UIViewController如可以看到下面:现在如何从的viewController的观点

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>) 

任何想法如何,我可以解决这个问题?

+0

我的代码?你的问题是你safari视图控制器是一个局部变量,它会在此函数退出时立即释放,大概是因为没有任何东西可以保留你的tableviewcontroller – Paulw11

回答

0

使用rootViewControllerSFSafariViewController是在这种情况下你的解决方案。你为什么不只是使用`UITableView`,而不是黑客了`UITableViewController`尝试以下

if (showLink) { 
    SFSafariViewController *sfsvc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.google.com"]]; 
    UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window; 
    [rootViewController.navigationController pushViewController:sfsvc animated:YES]; 
}