当从粉色区域中的灰色按钮调用时,func yesBtSetTextTo
打印不是nil,但是当从黄色按钮调用时,相同的func打印nil。我迷失在这一个。
我的主要veiwController.swift没有prepareForSegue
因为我没有在这里需要的东西。
有问题的func位于此代码块的末尾,
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")
}