senty senty - 2 years ago 122
Swift Question

IndexPath.row is not unique for Static Cells

I have a TableViewController with static cells and section headers. I tried to call

however, they are not unique.. For example

- Header 1
- Cell1 indexPath = 0
- Header 2
- Cell2 indexPath = 0
- Cell3 indexPath = 1
- Cell4 indexPath = 2

What is the proper way of getting unique identifiers for rows?

Because using this make 2 cells have the same indexPath

override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {

if indexPath.row != 0 {
return indexPath

return nil

Answer Source

You seem to be ignoring indexPath.section. The combination of section and row uniquely define the index path. A row is unique within its section.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download