将您的索引转换为字符串并附加您的自定义 url 方案
ProjectName://indexPath.row 作为字符串
最后基于索引
项目名称://1 项目名称://2
然后使用附加值重定向到您的主应用程序
let url = URL(string: "ProjectName://1")
extensionContext?.open(url!, completionHandler: nil)
它将调用您的主应用程序委托,您可以通过转换回Int来获取您的索引
func application(_ application: UIApplication, open urls: URL, sourceApplication: String?, annotation: Any) -> Bool {
let obj = urls.absoluteString.components(separatedBy: "://")[1]
//Here convert string to object back to int
NotificationCenter.default.post(name:"selectrow", object: obj)
return true
}
在您的视图控制器中观察它并将其转换为Int
在viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.navigateToPushnotificationScreen), name: "selectrow", object: nil)
然后添加这个方法
func navigateToPushnotificationScreen(notification : NSNotification){
let index = notification.object as! String
//Here convert your string object to Int, and select your tableview
}