当我在我的 tableview programatticaly 中单击一个单元格时,我一直在尝试打开一个 url,而不必制作一个 webview Controller 并弄乱 seques。关于如何完成这项工作的任何帮助。下面是我试过的代码
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
NSURL(string: "App Store Link")!
}
else if indexPath.row == 1 {
NSURL(string: "Send Us Feedback - Contact On Website")!
} else if indexPath.row == 2 {
NSURL(string: "https://www.instagram.com/prs_app/")!
} else if indexPath.row == 3 {
NSURL(string: "Snapchat")!
}
}
感谢您的帮助。谢谢
最佳答案
你在找
UIApplication.sharedApplication().openURL(NSURL(string: "http://www.example.com")!)
这将为您打开 safari 浏览器
在评论中编辑对问题的解释
如果你添加枚举或其他常量会更好,但这样做会:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let url : NSURL?
switch indexPath.section{
case 0:
switch indexPath.row{
case 0:
url = NSURL(string: "http://section0.row0.com")
case 1:
url = NSURL(string: "http://section0.row1.com")
default:
return;
}
case 1:
switch indexPath.row{
case 0:
url = NSURL(string: "http://section1.row0.com")
case 1:
url = NSURL(string: "http://section1.row1.com")
default:
return;
}
default:
return;
}
if url != nil{
UIApplication.sharedApplication().openURL(url!)
}
}
关于ios - 点击 swift 时 tableviewcell 打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37231463/