Answer the question
In order to leave comments, you need to log in
How to make a transition in the ViewController work when only one cell is clicked?
Hello! Can you advise plz.
There is a TableViewController and when only one cell is clicked (for example, indexPath.row == 2), the transition to the ViewController was made . Other cells should not be pressed) I
thought it was possible, like with didSelectRowAt , to come up with something, but it didn’t work out. There, all cells are pressed and transferred.
Answer the question
In order to leave comments, you need to log in
Selection style = none for cells, in didSelectRowAt, when the index and number of the desired cell match, we make a transition
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
cell.selectionStyle = indexPath.row == 1 ? .default : .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard indexPath.row == 1 else { return }
let vc = UIViewController()
navigationController?.pushViewController(vc, animated: true)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question