Search code examples
objective-ciosnsindexpath

Set NSIndexPath programmatically


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!


Solution

  • 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.