Swift 3 - Open URL from JSON in Safari

2019-09-21 07:27发布

I currently have a mobile app that brings in a list of items from a JSON file. The JSON file also has a list of urls attached to each item. I need to open the URL in Safari when the user touches the item in the list view.

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 
}

Does anyone have an idea on how to do this, I can post code to display how I bring in the list of data if necessary.

标签: ios json swift3
1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-21 07:47

Add this code:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    UIApplication.sharedApplication().openURL(NSURL(string:TableData[indexPath.row])!)
}
查看更多
登录 后发表回答