Set NSIndexPath programmatically

Matrosov Alexander picture Matrosov Alexander · Mar 22, 2012 · Viewed 21.6k times · Source

My question is: How to set NSIndexPath programmatically.

For example I add method:

- (void)setDefaultValue{
 tempIndexPath = [NSIndexPath indexPathForRow:0 inSection:1];
}

In tableView delegate -cellForRowAtIndexPath I want to compare two indexPath

if([indexPath isEqual:tempIndexPath]) ...

But in this case my tempIndexPath = null (i think - because this is autorelease object)

How to set NSIndexPath in this case?

Thanks, All!

Answer

LuisEspinoza picture LuisEspinoza · Mar 22, 2012

Add retain

- (void)setDefaultValue{
   tempIndexPath = [[NSIndexPath indexPathForRow:0 inSection:1] retain];
}

But you have to be aware of release temIndexPath in the future.

EDIT:I deleted bad option.