本人比较笨,下发的网页是我唯一能看懂,并上手抽取项目代码的网址(我也很绝望😔)
http://swift.gg/2016/06/01/protocol-oriented-views-in-swift/
这是我自己抽取的代码:
原来是在每个页面都要写上一个 方法。现在提取成:
import UIKit
protocol OpenAttachment {
}
extension OpenAttachment where Self: UIViewController {
func openAttWithCell(urlS:String) {
let application = UIApplication.shared
let urlser = urlS.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: urlser!)
if url != nil{
application.openURL(url!)
}else{
LJProgressHUD.showInfo(title: "没有文件路径")
}
}
}
在 UIViewController 中写入:
// OpenAttachment 就是 打开附件的协议
class LJDetailSubTaskVC: LJBaseViewController,OpenAttachment
// 点击后调用
// 获取URL地址
let listURL = attachmentArr[indexPath.row-1]["icon"] as? String
// 这个是URL 的地址。
self.openAttWithCell(urlS: listURL!)