0
我已經設置了一個協議,視圖控制器是該協議的代表,就像這樣:
import Foundation
protocol PayButtonProtocol {
func enablePayButton()
func disablePayButton()
}
而視圖控制器是委託:
class ViewController: UIViewController, PayButtonProtocol
協議功能如下:
func enablePayButton() {
println("Button enabled")
PAYBarButton.enabled = false
}
func disablePayButton() {
PAYBarButton.enabled = false
}
我設置一個類,並指定委託:
class Trigger
{
var delegate:PayButtonProtocol?
func EnablePayButton()
{
delegate?.enablePayButton()
}
}
然後我設置觸發運行功能:
let localtrigger = Trigger()
localtrigger.delegate = ViewController()
localtrigger.EnablePayButton()
這工作和「啓用按鈕」被顯示在控制檯中。但酒吧按鈕(PAYBarButton)是零,並且它似乎視圖控制器已經失去了它的hieracy,因爲我無法訪問任何視圖控制器對象。 View Controller使用界面構建器構建。任何人有任何想法?它是
localtrigger.delegate = ViewController()
重建viewconotroller並使原始不可訪問嗎?如果是這樣,我該怎麼做?