Swift 3 - 在Safari中从JSON打开URL

时间:2016-09-22 10:39:51

标签: ios json swift3

我目前有一个移动应用程序,可以从JSON文件中引入项目列表。 JSON文件还有一个附加到每个项目的URL列表。 当用户触摸列表视图中的项目时,我需要在Safari中打开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 
}

有没有人知道如何做到这一点,我可以发布代码来显示我如何在必要时引入数据列表。

1 个答案:

答案 0 :(得分:1)

添加此代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    UIApplication.sharedApplication().openURL(NSURL(string:TableData[indexPath.row])!)
}