Keyboard refuses to be dismissed

Hello everyone,

Below is the code to dismiss the keyboard by touching any area outside of the textfield

func hideKeyboard(gestureRecognizer: UIGestureRecognizer) {
    let point = gestureRecognizer.locationInView(tableView)
    let indexPath = tableView.indexPathForRowAtPoint(point)
    
    if indexPath == nil || !(indexPath!.section == 0 && indexPath!.row == 2) {
        conditionTextView.resignFirstResponder()
    }
}

And here’s where the function is called

override func viewDidLoad() {
super.viewDidLoad()

    if let location = locationToEdit {
        title = "Edit Details"
        if location.hasPhoto {
            if let image = location.photoImage {
                showImage(image)
            }
        }
        
    let gestureRecognizer = UITapGestureRecognizer(target: self, action:    Selector("hideKeyboard:"))
    gestureRecognizer.cancelsTouchesInView = false
    tableView.addGestureRecognizer(gestureRecognizer)
        
    }
    
    conditionTextView.text = descriptionText
    speciesLabel.text = speciesName
    temperamentLabel.text = temperamentName
    
    latLabel.text = String(format: "%.8f", coordinate.latitude)
    longLabel.text = String(format: "%.8f", coordinate.longitude)
    
    if let placemark = placemark {
        nearestAddressLabel.text = stringFromPlacemark(placemark)
    } else {
        nearestAddressLabel.text = "No Address Found"
    }
    
    dateLabel.text = formatDate(date)
    listenForBackgroundNotification()
}

And here’s the image of the keyboard being given the property of ‘Dismiss on drag’

Unfortunately the keyboard remains on the screen despite tapping anywhere on the screen or dragging. Is there something wrong with the code?

Thanks for reading.

Did you add a breakpoint or a log inside the hideKeyboard method to make sure its being called?

Hi there, did you get this to work?

Yep, got it to work but I can’t really remember what was wrong with the code. Thanks for asking!!