簡體   English   中英

如何從viewController的視圖中呈現UIViewController

[英]How to present UIViewController from viewController's view

我正在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>)

有什么想法可以解決這個問題嗎?

在這種情況下,使用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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM