I am trying to take contacts from my addressbook. I am displaying the data on my tableview. For that first I am setting the height of the tableviewcell.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
and after that I implement
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
I write the conditions and logic inside these delegate methods. But I am facing a problem where, the value of index path in both the methods are different. Due to this, while I am looping through the addressbook(inside these methods), both the delegate methods are being executed in a different order. Why is that the index path has different values in both cases
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathis only called just before the cell comes into view-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPathis called for all rows when the tableview is presented to get the total height of the tableview content.And I must also agree with @Vince comment that the only thing you should care about is that the methods are returning the correct value according to the given index path.
Normally you should load all the data needed for the tableview into, for example a
NSArray. Then just get the correct object from that array according to the indexpath.