我正在将FrontViewController
视图加载到我当前的视图控制器MyVideosViewController
。
我在MyVideosViewController
viewdidload()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playLatestvideoClick), name: latestKey, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playMostWatchedvideoClick), name: mostKey, object: nil)
在FrontViewController
//MARK: -Gesture Play
func playLatestvideoClick(sender: UITapGestureRecognizer)
{
print("----- PLAY GESTURE TAPPED ------")
let imgVw = sender.view as! UIImageView
api.selectedVideoID = String(imgVw.tag)
let homeviewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("MYVIDEO") as? MyVideosViewController
NSNotificationCenter.defaultCenter().postNotificationName(self.latestKey, object: nil)
}
func playMostWatchedvideoClick(sender: UITapGestureRecognizer)
{
print("----- PLAY GESTURE TAPPED ------")
let imgVw = sender.view as! UIImageView
api.selectedVideoID = String(imgVw.tag)
let homeviewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("MYVIDEO") as? MyVideosViewController
NSNotificationCenter.defaultCenter().postNotificationName(self.mostKey, object: nil)
}
这是我在FrontViewController
let tapPlay = UITapGestureRecognizer.init(target: self, action: (#selector(FrontViewController.playLatestvideoClick(_:))))
self.imgVideo.addGestureRecognizer(tapPlay)
self.imgVideo.userInteractionEnabled=true
但是当我点击手势时,这些方法中的任何一个都没有触发。这是什么原因? 请帮帮我。
更新
就像这样。如果我重新加载这个MyVideoViewController它第一次工作。然后它无法正常工作
答案 0 :(得分:0)
请尝试以下代码:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playLatestvideoClick(_:)), name: latestKey, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playMostWatchedvideoClick(_:)), name: mostKey, object: nil)
您需要传递此(_:)
之类的发件人,然后才会调用此方法。
希望这会对你有所帮助。