以编程方式设置NSIndexPath

Mat*_*der 13 objective-c nsindexpath ios

我的问题是:如何以编程方式设置NSIndexPath.

例如我添加方法:

- (void)setDefaultValue{
 tempIndexPath = [NSIndexPath indexPathForRow:0 inSection:1];
}
Run Code Online (Sandbox Code Playgroud)

在tableView委托-cellForRowAtIndexPath我想比较两个indexPath

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

但在这种情况下我的tempIndexPath = null(我认为 - 因为这是autorelease对象)

在这种情况下如何设置NSIndexPath?

谢谢,全部!

Lui*_*oza 22

添加保留

- (void)setDefaultValue{
   tempIndexPath = [[NSIndexPath indexPathForRow:0 inSection:1] retain];
}
Run Code Online (Sandbox Code Playgroud)

但是你必须知道将来发布temIndexPath.

编辑:我删除了错误的选项.