Swift 3 - 在Safari中使用JSON打开URL
问题描述:
我目前有一个移动应用程序,它带有来自JSON文件的项目列表。 JSON文件也有附加到每个项目的URL列表。 当用户触摸列表视图中的项目时,我需要在Safari中打开URL。Swift 3 - 在Safari中使用JSON打开URL
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = TableData[indexPath.row]
return cell
}
有没有人对如何做到这一点的想法,我可以张贴代码,以显示我如何在带来数据的列表中,如果必要的。
答
添加以下代码:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
UIApplication.sharedApplication().openURL(NSURL(string:TableData[indexPath.row])!)
}
+1
谢谢你会看看,只是意识到我需要两个添加一个主项目,然后进入子项目时首先选择。在我实现这个功能之前会解决这个问题 – mvoase
显示您的列表视图代码...'cellForRowAtIndexPath'和'DidSelectRow' –
不在这里,将它添加到你的问题,它会更容易阅读。 –
谢谢,我没有任何DidSelectRow,但我还没有那么远。 – mvoase