Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrease indexPath by one

I'm filling a TableView with CoreData.

Until now I was doing something like this:

        NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];

...to retrieve the object to fill the row.

Everything was working fine until I realized I have to manage the first row of the table as an exception because the first line will contain other content, not provided by CoreData.

Now my issue is how can I manipulate the indexPath to shift everything by one. I would like to do something like this:

// I know this is not going to work, just to give you an idea...
   NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath-1];

but I cannot find the right syntax to manipulate the indexPath. Can anyone help me? Thx for your time!

like image 610
Sr.Richie Avatar asked Nov 22 '11 17:11

Sr.Richie


People also ask

How does Swift compare to IndexPath?

The Swift overlay to the Foundation framework provides the IndexPath structure, which bridges to the NSIndexPath class. This means that, as an alternative to NSIndexPath , starting with Swift 3 and Xcode 8, you can use IndexPath . Note that IndexPath also conforms to Equatable protocol. Therefore, you can use == or !=

What does IndexPath mean in Swift?

In Swift, an indexPath is a list of indexes that, together, represent the path to a specific location in a tree of nested arrays. It describes an item's position inside a table view or collection view, storing both its section and its position inside that section.

What is IndexPath?

A list of indexes that together represent the path to a specific location in a tree of nested arrays.


1 Answers

In case we are talking about iOS UITableView index path there's much easier way:

NSIndexPath* newIndexPath = [NSIndexPath indexPathForRow:oldIndexPath.row+1 inSection:oldIndexPath.section];

Cheers... :)

like image 132
Ariel Avatar answered Sep 22 '22 14:09

Ariel