【发布时间】:2020-09-01 17:24:43
【问题描述】:
我有一个今天的扩展,它有一个UITableView。
当用户点击 UITableView 中的某个项目时,它会使用 URL 方案打开包含应用程序并传递一些数据,以便包含应用程序可以打开用户点击的项目的特定视图。
问题是,从 SceneDelegate.swift 我可以处理 URL 方案,但似乎我无法显示特定的 UITabBarController 并打开用户点击的项目的详细视图。
请注意,我并不是要创建它们;它们已经从情节提要中创建并正在工作。我只希望它自动“导航”,就像用户点击了 tableview 项目一样。
下面的代码是我试过的:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
// This part, I'm handling URL Scheme which is working fine
let url = URLContexts.first!.url
let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
let items = urlComponents?.queryItems
var deepLinkArray: [URLQueryItem] = []
deepLinkArray = items!
// From here I will use datas I got from URL
if let statusValue = deepLinkArray[0].value, let indexPathSection = deepLinkArray[1].value, let indexPathRow = deepLinkArray[2].value {
todoStatusValueURL = Int(statusValue)!
indexPathSectionURL = Int(indexPathSection)!
indexPathRowURL = Int(indexPathRow)!
// Here I want to show one of UITabBarController
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let snoozedVC = storyboard.instantiateViewController(withIdentifier: "SnoozedViewController") as! SnoozedViewController
snoozedVC.self.tabBarController?.selectedIndex = todoStatusValueURL! // And this is not showing what I want
// Additionally I want to show ItemDetailViewController as if user tapped the item in the tableview, and below code is also not working
let detailVC = storyboard.instantiateViewController(withIdentifier: "DetailVC") as! DetailVC
snoozedVC.navigationController?.pushViewController(detailVC, animated: true)
}
【问题讨论】:
-
试试
snoozedVC.tabBarController?.selectedIndex = todoStatusValueURL! -
tabBar 包含
SnoozedViewController?
标签: swift uiviewcontroller uitabbarcontroller today-extension uiscenedelegate