nithinsampath
nithinsampath

Reputation: 29

My outlets are not being referenced

Though I ctrl + drag, it gets referenced....but when I run the app it crashes with NSException... when I check on it says my view controller does not have an outlet named gif view and also the action check_internet is not defined on the view controller. The following is my view controller code.

import UIKit

extension UIViewController{
func checkreachability()
{
    if currentReachabilityStatus == .notReachable
    {
        let alert = UIAlertController(title: "No Internet ", message: "Please Check Your Internet Connection", preferredStyle: UIAlertControllerStyle.alert)

        // add an action (button)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))

        // show the alert
        self.present(alert, animated: true, completion: nil)
    }
}

ViewController:

class ViewController: UIViewController {

  @IBOutlet weak var gifview: UIImageView!

  override func viewDidLoad() {
    super.viewDidLoad()

    gifview.loadGif(name: "source")
    // Do any additional setup after loading the view, typically from a nib.
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  @IBAction func check_internet(_ sender: UIButton) { 
    checkreachability()
  }

}

Upvotes: 1

Views: 380

Answers (2)

Tej
Tej

Reputation: 71

Don't create weak reference. as weak references can not hold Remove weak from your @IBOutlet and try again

Upvotes: 0

Amal T S
Amal T S

Reputation: 3405

Remove the reference to the ViewController.swift. Then re-add it to the project, clean and build again.

Upvotes: 2

Related Questions