yumugee
yumugee

Reputation: 1003

EXC_BAD_ACCESS when using UITapGestureRecognizer

stuck for hours and still can't find the problem. I cannot add UITapGesture to two differentViews

@IBOutlet var topView: UIView
@IBOutlet var bottomView: UIView

userInteractionEnabled in topView and bottomView are enabled in storyboard

here's my code in ViewController.swift

override func viewDidLoad() {
    super.viewDidLoad()

    var tap = UITapGestureRecognizer(target: self, action: "tapTheView:")
    self.topView.addGestureRecognizer(tap)
    self.bottomView.addGestureRecognizer(tap)
}

this is the method for UITapGestureRecognizer

func tapTheView(recognizer: UITapGestureRecognizer) {

    println("Hi")

}

but when I clicked the topView nothing happened, when I clicked the bottomView my app crash and show Thread 1: EXC_BAC_ACESS in this line

class AppDelegate: UIResponder, UIApplicationDelegate {

I'm using Xcode 6 beta 2.

when I tried it in XCode 5.1.1 using the same code above (but with objective-c) it works. thanks you very much and sorry for my bad English

Upvotes: 2

Views: 717

Answers (1)

Yatheesha
Yatheesha

Reputation: 10432

This works without crash in Xcode beta 2. One thing is you have to add separate gestures for each view Check this link. i.e

var tap = UITapGestureRecognizer(target: self, action: "tapTheView:")
self.topView.addGestureRecognizer(tap)

var tap2 = UITapGestureRecognizer(target: self, action: "tapTheView:")
self.bottomView.addGestureRecognizer(tap2)

Upvotes: 2

Related Questions