Arg*_*oto 1 xcode uitableview ios presentviewcontroller swift
以下代码在 a 中工作UIViewController,但在我的类中,UITableViewCell它给出了错误
使用未解析的标识符“存在”。
代码是一个动作:
@IBAction func linkAction(_ sender: Any) {
let linkString = self.linkText.text
if let requestUrl = URL(string: linkString!) {
let safariVC = SFSafariViewController(url: requestUrl)
present(safariVC, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
有解决办法吗?
在主 UIViewController 中:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "idCell", for: indexPath)
cell.viewController = self
}
Run Code Online (Sandbox Code Playgroud)
在 UITableViewCell 类中:
class TableViewCell: UITableViewCell {
weak var viewController: UIViewController?
@IBAction func linkAction(_ sender: Any) {
let linkString = self.linkText.text
if let requestUrl = URL(string: linkString!) {
let safariVC = SFSafariViewController(url: requestUrl)
viewController?.present(safariVC, animated: true, completion: nil)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1575 次 |
| 最近记录: |