我使用UITableViewController
中UIViewController
的视图,如下所示:
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 :(得分:0)
在这种情况下,使用rootViewController
推送SFSafariViewController
是一种解决方案。试试下面的代码
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];
}