Swift 3 - Open URL from JSON in Safari

主宰稳场 提交于 2019-12-13 08:57:16

问题


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.


回答1:


Add this code:

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


来源:https://stackoverflow.com/questions/39636818/swift-3-open-url-from-json-in-safari

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!