我有一个 Today Extension,它有一个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)
}