ARNON
ARNON

Reputation: 1217

Unexpected SafariViewController reaction

I have an app with some Table View Controllers. In the last one of each cell I have a different url. I decided then to insert a SafariVC, but what is occurring is that it is like it was as a FirstResponder.

class Page3: UITableViewController, GADBannerViewDelegate, SFSafariViewControllerDelegate {

    ...

    @IBOutlet weak var websiteTextView: UITextView!

    ...

    override func viewDidLoad() {
        super.viewDidLoad()

        ...

        websiteTextView.text = goP3.website

        let safariVC = SFSafariViewController(url: URL(string: goP3.website)!)
        present(safariVC, animated: true, completion: nil)
        safariVC.delegate = self

        ...
    }
}

gif

After watch the gif above, I have two doubts:

1st. When I go into the Page3, it auto-opens the SafariViewController. How do I fix it?

2st. When I click on the url, it doesn't open the SafariViewController. What do I have to do to fix it?

Upvotes: 0

Views: 207

Answers (1)

krunal
krunal

Reputation: 482

For 1) 1st Question answer is below: You need to remove below code from ViewDidLoad Method:

websiteTextView.text = goP3.website
let safariVC = SFSafariViewController(url: URL(string: goP3.website)!)
present(safariVC, animated: true, completion: nil)
safariVC.delegate = self

For 2) 2nd Question answer is below: You need to create a UIButton and set title text for goP3.website. Then Create IBAction method for that UIButton. something like below

@IBOutlet weak var btnWebsite: UIButton!
override func viewDidLoad() {
    super.viewDidLoad()

    ...
    btnOK.setTitle(goP3.website, for: .normal)
}
@IBAction func btnWebsiteSelect(_ sender: UIButton) {

    let safariVC = SFSafariViewController(url: URL(string: goP3.website)!)
    present(safariVC, animated: true, completion: nil)
    safariVC.delegate = self
}

Upvotes: 1

Related Questions