虽然我按住Ctrl +拖动它会被引用....但是当我运行应用程序时它崩溃了NSException ...当我检查它时说我的视图控制器没有名为gif视图的插座以及动作check_internet未在视图控制器上定义。以下是我的视图控制器代码。
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()
}
}
答案 0 :(得分:1)
删除对ViewController.swift
的引用。然后将其重新添加到项目中,再次清理并构建。
答案 1 :(得分:0)
不要创建弱引用。
因为弱引用无法成立
从@IBOutlet
删除弱点,然后重试