M
M
MarsFM2016-11-17 21:27:41
iOS
MarsFM, 2016-11-17 21:27:41

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

1 answer(s)
M
ManWithBear, 2016-11-17
@sportredwhite

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 question

Ask a Question

731 491 924 answers to any question