Reputation: 156
The following code works in a UIViewController
, but in my class thats a UITableViewCell
it's giving the error
Use of unresolved identifier 'present'.
The code is an action:
@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)
}
}
Is there a fix?
Upvotes: 1
Views: 1619
Reputation: 687
In the main UIViewController:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "idCell", for: indexPath)
cell.viewController = self
}
In the UITableViewCell class:
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)
}
}
}
Upvotes: 8
Reputation: 457
You need to communicate back to the ViewController that presents this TableView. Either with a remote notification, or delegate.
Upvotes: 0