my long press gesture recognizer causing action event executed twice?
i trying figure out warning: attempt present vc2 on vc1 view not in window hierarchy!
by using println() tests, found vc2 being presented twice.
my vc2 presentation method:
p1long:uilongpressgesturerecognizer located on vc1's mainview
when long press done on p1
of vc1
@ibaction func presentplayerinfo(sender: uigesturerecognizer){ var loc = sender.locationinview(self.view) var segueswitch = 0 if (cgrectcontainspoint(self.p1.frame, lock)) { tappedview = self.p1; segueswitch = 1 } else if (cgrectcontainspoint(self.redeal.frame, lock)) { tappedview = self.redeal; segueswitch = 2 } if segueswitch == 1 { performseguewithidentifier("playerstable", sender: self) println("playerstable") } else if segueswitch == 2 { self.viewdidload() } }
console output:
playerstable playerstable warning: attempt present <ipro_poker_hh_swift.vc2: 0x14555470> on <ipro_poker_hh_swift.vc1: 0x153a2600> view not in window hierarchy!
why longpress acting twice.
you should handle long press gesture recognizer's state. uilongpressgesturerecognizer's action invokes on it's state changes. receiving first time when state == uigesturerecognizerstatebegan , second time when uigesturerecognizerstateended.
you need like:
if (recognizer.state == uigesturerecognizerstateended) { //your action }