Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 332
Matrosov Oleksandr Avatar asked Mar 22 '12 13:03

Matrosov Oleksandr


2 Answers

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.

like image 94
LuisEspinoza Avatar answered Oct 07 '22 23:10

LuisEspinoza


Simply call retain after you instantiated it:

[tempIndexPath retain];

This will make you the owner of the object, so remember to release it when you have done.

like image 43
Manlio Avatar answered Oct 07 '22 22:10

Manlio