【发布时间】:2017-01-13 12:46:02
【问题描述】:
我创建了 UIAlertView,它有 2 个正按钮和负按钮。 AlertView 也是视图控制器。
我正在从 Main viewController 打开 AlertVC。
这是我的 AlertVC
class AlertVC: UIViewController {
var transitioner : CAVTransitioner
@IBOutlet weak var alertPositiveBtn: IFOButton!
@IBOutlet weak var alertNegativeBtn: IFOButton!
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
self.transitioner = CAVTransitioner()
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.modalPresentationStyle = .custom
self.transitioningDelegate = self.transitioner
}
convenience init() {
self.init(nibName:nil, bundle:nil)
}
required init?(coder: NSCoder) {
fatalError("NSCoding not supported")
}
@IBAction func postiveBtnPressed(_ sender: IFOButton) {
}
@IBAction func negativeBtnPressed(_ sender: IFOButton) {
}
@IBAction func closeBtnPressed(_ sender: UIButton) {
self.presentingViewController?.dismiss(animated: true, completion: nil)
}
}
我想要什么:我希望 MainViewController 以某种方式检测按下哪个按钮是负的还是正的。
有人能告诉我怎么做吗?
更新:使用委托模式后
@IBAction func positiveBtnPressed(_ sender: IFOButton) {
delegate?.positiveBtnPressed(onAlertVC: self)
self.presentingViewController?.dismiss(animated: true, completion: nil)
}
@IBAction func negativeBtnPressed(_ sender: IFOButton) {
delegate?.negativeBtnPressed(onAlertVC: self)
self.presentingViewController?.dismiss(animated: true, completion: nil)
}
这是我在 MainViewController 上所做的
class MainViewController: UIViewController, AlertVCDelegate
这是我的功能
func positiveBtnPressed(onAlertVC: IFOAlertVC) {
print("Pos")
}
func negativeBtnPressed(onAlertVC: IFOAlertVC) {
print("Neg")}
它仍然没有被调用。
【问题讨论】:
-
请给标签值 alertPositiveBtn 和 alertNegativeBtn 你可以在你的控制器上传递这个标签值
-
您可以使用
delegate/protocol。
标签: ios iphone swift uibutton swift3