ios - UITableView didSelectRowAt indexPath not called in custom cell -
i create new viewcontroller , drag new uitableview works, in previous 2 viewcontrollers cannot work.
all following done:
- uitableviewdelegate .delegate=self
- uitableviewdatasource .datasource=self
- swift3 , didselectrowat not diddeselectrowat
- .setediting(true, animated: true)
- .allowsselection = true
- .allowsselectionduringediting = true
- singelselection
and data can load tableview, thing cannot select rows, in mainviewcontroller have 1 table view, 1 used testing.
 -this 1 of viewcontroller tableview cannot select row can load data, here have 1 tableview, test create new table view
 -this 1 of viewcontroller tableview cannot select row can load data, here have 1 tableview, test create new table view
 -this second viewcontroller cannot select row
 -this second viewcontroller cannot select row
this mainviewcontroller
extension mainviewcontroller: uitableviewdelegate, uitableviewdatasource {      func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {          return 10     }      func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {          if tableview == self.tableview_restaurants {              let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) as! restaurantscell              cell.label_name.text = "omg restaurant # \(string(indexpath.row))"              return cell         }         else if tableview == self.tableview_test {              let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) as! tableviewtestcell              cell.label_test.text = string(indexpath.row)              return cell         }         else {             let cell = uitableviewcell()              return cell         }     }      func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) {          //tableview.deselectrow(at: indexpath, animated: true)         if tableview == self.tableview_restaurants {          }         else if tableview == self.tableview_test {             print("select row")             print(indexpath)         }     } } this filterviewcontroller
extension searchfilterviewcontroller: uitableviewdelegate, uitableviewdatasource {       func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {          var numberofrowsinsecion:int = 0          if (tableview == self.tableview_quickfilters) {              numberofrowsinsecion = json_quickfilters["filters"].arrayvalue.count             //print(numberofrowsinsecion)         }          else if (tableview == self.tableview_cuisinetype) {             numberofrowsinsecion = json_cuisinetype["cuisine_types"].arrayvalue.count             //print(numberofrowsinsecion)         }          return numberofrowsinsecion     }       func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {          if (tableview == self.tableview_quickfilters) {              let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) as! quickfilterscell              let filter = json_quickfilters["filters"].arrayvalue              if let filter_name = cell.label_quickfiltersname {                  filter_name.text = filter[indexpath.row]["name"].stringvalue                 filter_name.font = common.config.fontsize.xl_l             }             return cell         }          else if (tableview == self.tableview_cuisinetype) {              let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) as! cuisinetypecell              let cuisinetype = json_cuisinetype["cuisine_types"].arrayvalue              if let cuisinetype_name = cell.label_cuisinetypename {                  cuisinetype_name.text = cuisinetype[indexpath.row]["name"].stringvalue                 cuisinetype_name.font = common.config.fontsize.xl_l             }             return cell         }          else {             let cell = uitableviewcell()             return cell         }      }       func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) {          if (tableview == self.tableview_quickfilters) {              print(indexpath)              //let cell = tableview.cellforrow(at: indexpath) as! quickfilterscell          } else if (tableview == self.tableview_cuisinetype) {              print(indexpath)              //let cell = tableview.cellforrow(at: indexpath) as! cuisinetypecell          }      }  } 
you have added tap gesture somewhere cancels cell taps. check answer here: https://stackoverflow.com/a/9248827/1286291
Comments
Post a Comment