Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSInteger to NSIndexpath

Basically I am storing an index of an array in a NSInteger. I now need it as an NSIndexpath, I'm struggling to see and find a way to convert my NSInteger to NSIndexpath so I can reuse it.

like image 449
Dan Avatar asked Jun 23 '11 13:06

Dan


2 Answers

For an int index:

NSIndexPath *path = [NSIndexPath indexPathWithIndex:index]; 

Creates Index of the item in node 0 to point to as per the reference.

To use the indexPath in a UITableView, the more appropriate method is

NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section]; 
like image 194
ageektrapped Avatar answered Sep 24 '22 08:09

ageektrapped


If you need a NSIndexPath for a UITableView, you can use indexPathForRow:inSection: (reference). Index paths passed to table view must contain exactly two indices specifying the section and row. An index path created with indexPathWithIndex: only contains one index and won't work with a table view.

like image 35
albertamg Avatar answered Sep 26 '22 08:09

albertamg