【发布时间】:2017-04-02 20:14:23
【问题描述】:
我的协议根本没有触发,我正在使它符合我希望它触发的方法。任何帮助将不胜感激!
public class NoteCardView:UIView {
@IBInspectable var delegate: NoteCardViewDelegate?
func handleTitleLabelTap(_ recognizer:UITapGestureRecognizer) {
// Verified this function is being called and has the right value!
self.delegate?.noteCardViewTitleLabelDidRecieveTap(MainViewController.NoteCardArray[Int(recognizer.view!.tag)])
}
}
public protocol NoteCardViewDelegate {
// This should be being fired..
func noteCardViewTitleLabelDidRecieveTap(_ view: NoteCardView!)
}
extension MainViewController: NoteCardViewDelegate {
// this is what the handleTitleLabelTap function should do!
func noteCardViewTitleLabelDidRecieveTap(_ view: NoteCardView!) {
print("6")
let card:NoteCardView = (view)
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
card.contentView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: (self.elementPlacement / 4) + 20)
card.contentView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 100)
}, completion: { (finished: Bool) in
self.elementPlacement = (self.elementPlacement + 1)
card.titleLabelTapGestureRecognizer!.isEnabled = !(self.elementPlacement == 5)
})
}
}
【问题讨论】:
-
为什么要删除之前的问题?设置点击手势的代码在哪里?
-
@rmaddy 我意识到我之前的问题措辞不当并且有多余的代码。我的点击手势的代码在测试后确实有效,我输入了打印语句并发现它正在触发方法 handleTitleLabelTap。 handleTitleLabelTap 现在没有触发协议,因此这个问题。很抱歉造成混乱!
-
显然
self.delegate是nil。在确认这是真的之后找出原因。
标签: ios swift uibutton uitapgesturerecognizer