why tableview cell is selecting only after holding the cell?

I'm facing a weird bug in Xcode. I cannot select the tableview cell with one tap on it, I need to hold it for a second to select it. I applied DIDSELECT ROWAT method for selecting the cell. What should I do to make tableview cell selecting in one quick tap?
The problem is not in Xcode but when you run the app, right ?
Is it in simulator or on device ?

Have you defined actions for longPress somewhere ?
No, I haven't specified any longPress action. I'm facing this problem on my device, as well as on simulator.

Which Xcode version ?

Have you a small project to attach, so that we can test also ?
Xcode Version: 11.5 (11E608c)

I can send you the code of that page, which is as follows:

//
// SearchFriendVC.swift
// iSEN
//
// Created by Rahul Pawar on 14/07/20.
// Copyright © 2020 Schnell Technologies. All rights reserved.
// , UISearchResultsUpdating

import UIKit
import Firebase
import FirebaseUI

class SearchFriendVC: UIViewController, UISearchResultsUpdating {
   
   

  @IBOutlet weak var tableView: UITableView!
  // @IBOutlet weak var searchBar: UISearchBar!
   
  //var usersArray : [SearchDataModel] = [SearchDataModel]()
  var userArray = [NSDictionary?]()
  var filteredUser = [NSDictionary?]()
  let searchController = UISearchController(searchResultsController: nil)
  var user: NSDictionary?
   
  var ref = Database.database().reference()
   
   
  override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
     
    tableView.delegate = self
    tableView.dataSource = self
     
     
     
    hideKeyboardWhenTappedAround()
     
     
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    definesPresentationContext = true
    searchController.searchBar.isTranslucent = true
    searchController.searchBar.tintColor = .purple
    searchController.searchBar.searchBarStyle = .minimal
    searchController.searchBar.searchTextField.textColor = .black
    tableView.tableHeaderView = searchController.searchBar
//
    //tableView.allowsSelection = true
     
    tableView.register(UINib(nibName: "SearchResultTVC", bundle: nil), forCellReuseIdentifier: "searchResultCell")
     
     
   // retriveData()
     
     
     
    ref.child("All Users").queryOrdered(byChild: "Name").observe(.childAdded) { (snapshot) in
      self.userArray.append(snapshot.value as? NSDictionary)
      self.tableView.insertRows(at: [IndexPath(row: self.userArray.count-1, section: 0)], with: UITableView.RowAnimation.automatic)
       
    }
  }

   
  @IBAction func messageBtnPressed( sender: UIButton) {
     
    let messageVC = self.storyboard?.instantiateViewController(identifier: "HomeVC") as! HomeVC
    show(messageVC, sender: self)
     
  }
 
   
   
  func updateSearchResults(for searchController: UISearchController) {
    filterContent(searchText: self.searchController.searchBar.text!)

  }
   
   
   

   
   
  func filterContent(searchText: String){

    self.filteredUser = self.userArray.filter{ user in
      let userName = user!["Name"] as? String
      let userProfile = user!["Profile Image"] as? String
      let userID = user!["UserID"] as? String


      return (userName?.lowercased().contains(searchText.lowercased()))!
    }
    tableView.reloadData()
  }
   
   

  

}


extension SearchFriendVC: UITableViewDataSource, UITableViewDelegate{
  func numberOfSections(in tableView: UITableView) -> Int {
    return 1
  }
  func tableView(
tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if searchController.isActive && searchController.searchBar.text != ""{
      return filteredUser.count
    }
    return userArray.count
  }
  func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "searchResultCell", for: indexPath) as! SearchResultTVC
     
     
     
     
    if searchController.isActive && searchController.searchBar.text != ""{
      user = filteredUser[indexPath.row] as? NSDictionary
     
    }else{
      user = userArray[indexPath.row] as? NSDictionary
    }

    cell.nameLabel.text = user?["Name"] as? String
    let profileImage = user?["Profile Image"] as! String

    cell.profileImage.sd
setImage(with: URL(string: profileImage), completed: nil)

     
    return cell
  }

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
    tableView.deselectRow(at: indexPath, animated: true)
     
    

    if searchController.isActive && searchController.searchBar.text != ""{
          user = filteredUser[indexPath.row] as? NSDictionary

      let userId = filteredUser[indexPath.row]
      print("###########,\(userId?["UserID"])")
      let uid = userId?["UserID"] as! String
      UserDefaults.standard.set(uid, forKey: "savedFilteredUserID")
      performSegue(withIdentifier: "goToFrirndProfile", sender: self)

        }else{
          user = userArray[indexPath.row] as? NSDictionary


      let userID = userArray[indexPath.row]
      print("$$$$$$$$$$$$$$$$$,\(userID?["UserID"])")
        }

      }
   


}


Why do you deselect in didSelect ?

Try removing this.

If you want a single selection, define in Attributes Inspector the tableView as Single selection.
Or if you want to deselect if selected, test if the cell is selected before.
I have removed deselect in didSelect.
But still facing same problem 😔



Could you describe the exact scenario:

Code Block
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if searchController.isActive && searchController.searchBar.text != "" {
user = filteredUser[indexPath.row] as? NSDictionary
let userId = filteredUser[indexPath.row]
print("###########,\(userId?["UserID"])")
let uid = userId?["UserID"] as! String
UserDefaults.standard.set(uid, forKey: "savedFilteredUserID")
performSegue(withIdentifier: "goToFrirndProfile", sender: self)
} else {
user = userArray[indexPath.row] as? NSDictionary
let userID = userArray[indexPath.row]
print("$$$$$$$$$$$$$$$$$,\(userID?["UserID"])")
}
}


Does it occur in the if (6-11) as well as in the else (13-15): do you get the print if you just tap ?

Also try to comment out the performSegue, (replace by a simple print) to check if it is the cause of problem.
Have you a prepare for segue ?
If so, please post.

I tried to print on tap, for that also I had to hold the cell.
Well, there may be some project setting that is causing the problem. But we would need to get a full project folder to check…
where can I send full project folder?

why tableview cell is selecting only after holding the cell?
 
 
Q