我正在開發一個應用程序,我需要一個委託方法來確定哪個按鈕被user.Below所代碼,請讓我知道我犯的錯誤.Delegate不工作,沒有錯誤,沒有崩潰。Swift中的自定義委託方法
import UIKit
@objc protocol SAlertViewDelegate {
optional func clickedButtonTitle(title:String)
}
class CustomAlertView: UIView {
var delegate:SAlertViewDelegate?
func button1Action(sender: UIButton?) {
let titleLabel=sender?.titleLabel?.text
self.delegate?.clickedButtonTitle!(titleLabel!)
removeFromMainView()
}
}
視圖控制器: -
import UIKit
class CurrentImageVC: UIViewController,SAlertViewDelegate
{
var alert:CustomAlertView=CustomAlertView()
override func viewDidLoad() {
super.viewDidLoad()
alert.delegate=self
}
//MARK: Custom Delegate
func clickedButtonTitle(title:String)
{
println(title)
}
}
你是如何呈現你的CustomAlertView? –
讓alertSubView = CustomAlertView() alertSubView.frame = CGRectMake(0,0,1024,768) self.view .addSubview(alertSubView) – Saurabh