views:

45

answers:

2

I have a tableView controller with two sections. The first section has a couple of input fields and is not really displaying core data. The second section displays items from a database saved with Core Data.

I have an NSFetchedResultsController and I serve up data for cellForRowAtIndexPath and didSelectRowAtIndexPath as follows. For section = 0, I manually serve up the appropriate input fields, and for section = 1 I want to use [fetchedResultsController objectAtIndexPath:indexPath]. () However, since the fetched results controller only knows about one section, this doesn't work.

I know I can create a new IndexPath with section = 0, and then feed that to the NSFetchedResultsController. Is that the preferred solution or is there another way to 'tell' the NSFetchedResultsController what to expect?

+1  A: 

Why would you need to tell it anything? In the delegate methods, just offset the section index by one and you should be fine.

You can create your own NSIndexPath instance to pass into the NSFetchedResultsController to resolve this issue.

Update

If you want to have two sections then yes that is the right answer. However I would consider putting your input fields into the table header instead of a section. That would be a cleaner answer in my opinion.

Marcus S. Zarra
right...my question was "is creating a new `NSIndexPath` the best method or is there a better way?" apparently not, judging by the lack of commentary.
unsorted
+1  A: 

The only way to do this is to translate the NSIndexPath objects passed into the various UITableViewDataSource/UITableViewDelegate methods into index paths appropriate for your NSFetchedResultsController. I'd recommend adding a method to your class that does this.

The return values from this method will match the section numbers the NSFetchedResultsController uses. Also, if in the future you end up needing a second header section for whatever reason, it's easy enough to adjust your method to do that.

Alex