gesture recognizer issue with tic tac toe in xcode

hello there i am trying to figure out what the issue is why i cant get a cross on the game board when a tap is made. the TTT class is the one below the first code and it is called in the main code. i will appreciate if some can help me on this

@IBOutlet var fields: [TTTImageView]!

override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.


func fieldTapped (recognizer:UITapGestureRecognizer)    {
        let tappedField = recognizer.view as! TTTImageView
    tappedField.setPlayer(_player: "x.png")


func setupField ()  {
    for index in 0 ... fields.count - 1 {

        let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(fieldTapped))
        gestureRecognizer.numberOfTapsRequired = 1




import UIKit

  • NSUndoManager casting NSUndoManagerProxy crash in Swift code
  • Swift UITableView delegate and dataSource declaration and retain cycles
  • Core Data NSPredicate fetch on entity relationship using in clause
  • Swift: setting an optional property of a protocol
  • Swift : Error: 'required' initializer 'init(coder:)' must be provided by subclass of 'UIView'
  • 'var' parameters are deprecated and will be removed in Swift 3
  • class TTTImageView: UIImageView {

    var player:String?
    var activated:Bool! = false
    func setPlayer  (_player:String)    {
        self.player = _player
        if activated == false   {
            if _player == "x.png"   {
                self.image = UIImage (named: "x.png")
                self.image = UIImage (named: "o.png")
            activated = true


    Solutions Collect From Internet About “gesture recognizer issue with tic tac toe in xcode”

    Make sure when you set fields[index].addGestureRecognizer(gestureRecognizer) to set isUserInteractionEnabled to true.

    fields[index].isUserInteractionEnabled = true

    Whenever you want to detect user activity (e.g. UITapGestureRecognizer on a UIImageView, you need to set this to true


    I also wanted to mention something I noticed after looking at your code again: the method you are using for selectors has been deprecated. If you are using Swift 3 (which I highly recommend you do), you shouldn’t call selectors like this: "functionName:" anymore. Now we use selectors like so: #selector(functionName(_:)). You should start updating your code to the most current syntax sooner rather than later.