我在DetailVC中设置SFSafariViewController。我需要在哪里设置编码来解决错误:



该错误显示在:safariVC.delegate = self旁边。

import SafariServices
import UIKit

class StateDetailViewController: UIViewController, SFSafariViewControllerDelegate {

    @IBAction func watchButtonTapped(_ sender: SAButton) {
      if let url = URL(string: self.state!.url) {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
        let safariVC = SFSafariViewController(url: url)
        present(safariVC, animated: true)
      }
      safariVC.delegate = self
  }
  @IBOutlet weak var stateTitleTextLabel: UILabel!
  @IBOutlet weak var stateDetailTextTitleLabel: UILabel!
  @IBOutlet weak var stateDescriptionTextView: UITextView!

  var state: State?

  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    title = "Reciprocal Details"

    stateTitleTextLabel.text = state?.title
    stateDetailTextTitleLabel.text = state?.detailText
    stateDescriptionTextView.text = state?.description

    func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
      controller.dismiss(animated: true, completion: nil)
    }
  }

}

最佳答案

更改

  if let url = URL(string: self.state!.url) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
    let safariVC = SFSafariViewController(url: url)
    present(safariVC, animated: true)
  }
  safariVC.delegate = self


  if let url = URL(string: self.state!.url) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
    let safariVC = SFSafariViewController(url: url)
    safariVC.delegate = self
    present(safariVC, animated: true)
  }

关于swift - 如何解决编码错误: “Use of Unresolved Identifier SafariVC” . The error is next to “SafariVC.delegate = self” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55908036/

10-13 23:50