当从粉红色区域的灰色按钮调用时, funcyesBtSetTextTo
不打印 nil,但从黄色按钮调用时,相同的 func 打印 nil。我迷路了。
我的主要 veiwController.swift 没有,prepareForSegue
因为我在这里不需要它。
有问题的函数位于此代码块的末尾,
MainBtVC.swift
protocol MainBtDelegate {
func yesBtSetTextTo(name: String)
}
class MainBtVC: UIViewController, MainBtDelegate {
@IBOutlet weak var yesBt: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func yesBtSetTextTo(name: String) {
print("called")
if yesBt == nil {
print("button is nil")
} else {
print("button not nil")
}
// yesBt.setTitle("Exit", forState: UIControlState.Normal)
}
@IBAction func yesBtTapped(sender: AnyObject) {
yesBtSetTextTo("dummy")
}
TopVC.swift
class TopVC: UIViewController {
var delegate: MainBtDelegate?
override func viewDidLoad() {
super.viewDidLoad()
delegate = MainBtVC()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func buttonTapped(sender: AnyObject) {
delegate?.yesBtSetTextTo("Exit")
}