Search code examples
iosuitableviewnsindexpath

iOS: How to pass index of row which is in section


I have a tableview structure like this,

Section 1

----> Row 1

----> Row 2

----> Row 3

Section 2

----> Row 1

----> Row 2

Section 3

----> Row 1

----> Row 2

----> Row 3

----> Row 4

How to get index of particular row that I have to pass, like i have to get index of 2nd row from 3rd section ? Consider I have to pass exact address/index/location of 2nd row from 3rd section.


Solution

  • You can create a subclass of UITableViewCell, and add two properties to it

    @property (nonatomic) NSInteger row;
    @property (nonatomic) NSInteger section;
    

    then in the cellForRowAtIndexPath: method you can set these values according to the index path.

    and once you want to pass the row&section info just use delegation or KVO