Swift 3-在Safari中从JSON打开URL [英] Swift 3 - Open URL from JSON in Safari

查看:131
本文介绍了Swift 3-在Safari中从JSON打开URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个移动应用程序,该应用程序从JSON文件中引入项目列表. JSON文件还具有附加到每个项目的URL列表. 当用户触摸列表视图中的项目时,我需要在Safari中打开URL.

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.

推荐答案

添加此代码:

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

这篇关于Swift 3-在Safari中从JSON打开URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆