我的网点没有被引用
My outlets are not being referenced
虽然我按 ctrl + 拖动,但它被引用了....但是当我 运行 应用程序崩溃时出现 NSException...当我检查它时说我的视图控制器没有名为 outlet 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()
}
}
删除对 ViewController.swift
的引用。然后重新添加到项目中,清理并再次构建。
不要创建弱引用。
因为弱引用无法保持
从您的 @IBOutlet
中删除 weak 并重试
虽然我按 ctrl + 拖动,但它被引用了....但是当我 运行 应用程序崩溃时出现 NSException...当我检查它时说我的视图控制器没有名为 outlet 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()
}
}
删除对 ViewController.swift
的引用。然后重新添加到项目中,清理并再次构建。
不要创建弱引用。
因为弱引用无法保持
从您的 @IBOutlet
中删除 weak 并重试