我正在处理这种情况,我想在这里应用 RxSwift。
我有.xib
带按钮的 UIView。
class RightButtonItemView: UIView {
@IBOutlet weak var rightButtonimageView: UIImageView!
@IBOutlet weak var rightButtonButton: UIButton!
let performEventSegue = PublishSubject<Bool>()
class func instanceFromNib() -> RightButtonItemView {
return UINib(nibName: "NotificationView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! RightButtonItemView
}
override func awakeFromNib() {
//I'm not sure how should I link button tap and my subject
rightButtonButton.rx.tap
}
}
我在我的 viewController 中创建了这个视图的一个实例
var rightButtonItemView = RightButtonItemView.instanceFromNib()
从我的 segue 中单击此按钮我需要转到下一个 VC,所以我订阅了 UIView 的主题
rightButtonItemView.performEventSegue.asObserver().subscribe(onNext: { (isAuthorized) in
if isAuthorized {
let storyboard = UIStoryboard(name: "Notifications", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "UserNotificationsViewController")
self.present(viewController, animated: true, completion: nil)
}
})
但是我不知道如何将按钮点击与我的发布主题的更改状态联系起来?