Jure
Jure

Reputation: 3043

iPhone - UITableViewController and Core Data rows repeating in tableView

I am new to Cocoa and Core Data and I've encountered a weird problem. I successfully created the Core Data model, imported the data, made the UI (Navigation controller, tableViewController with searcDdisplayController) but now I'm stuck at one problem. If I implement a UITableViewController (with no UITableView in the nib file), the results fetched from fetchedResultsController are weird - the row count is correct (500 rows), but they are repeating themselves - only 8 different rows.

However, I was able to fix this problem by adding @synthesize tableView; in the .m file.

Then i encountered another problem - when i click on a row and push the details view, then click the back button on the Navigation Controller, the selected row in the tableView is still selected.

I hope I am being clear on what's wrong. Let me recap: If I don't put the @synthesize tableView; on the top of the implementation file, the deselection of the row is working fine, but the results are wrong - 8 rows (out of 500) repeating in the tableView. If I put the @synthesize in the file, the data in the tableView is correct, but there is no animation when i get back to the tableView with the navigation controller.

I also tried to put a UITableView in the nib file of the listviewcontroller, but the results were the same - no deselection of the row. I also tried to deselect row in the viewWillAppear delegate, but the indexPath of the indexPathForSelectedRow is null.

Oh, and I'm using an NSFetchedResultsController. Like I said - the fetched results are correct, but it seems that they're not properly fed to the tableview (if it is not synthesized..)

Thanks!

Upvotes: 1

Views: 621

Answers (2)

Jure
Jure

Reputation: 3043

Thanks for responding!

Hmm..I may have found a solution, but I'm not sure it's correct.. I am implementing the UITableViewController in my new class, but I'm actually using a new UITableView (tableView2) for the data fetching. In the nib file i created the UITableViewController, set the Class name to my custom class BUT I didn't connect the Table View in the Interface Builder with my newly created tableView2. I hope you'll be able to understand.. It's quite complicated, this whole stuff :S

So if I get this right - if I implement an UITableViewController, my class automatically gets a self.tableView? But, like I said in my question, if I don't synthesize the property in the .m file, the controller can't deselect the row automatically..but if I do, the data isn't correct and is repeating..Maybe there is a problem in the cellForRowAtIndexPath, where i get my cells from self.tableView..but It's not logical :S

Anyway, now the row de-selection animation works without my interference and the data displayed is correct. I'm suspecting that the UITableViewController has some other methods that need to be overwritten if using the NSFetchedResultsController.

Do you think my method is incorrect? Having a new UITableView in my custom UITableViewController class?

Upvotes: 0

DerekH
DerekH

Reputation: 860

I might be able to solve your row highlighting issue but you will need to include some code examples so we can help you with the other items...

To deselect a row you can call the method [deselectRowAtIndexPath:animated:] this will allow you to deselect the row before or after you push your detail view controller from your tableView selection delegate. Table View Reference

Upvotes: 1

Related Questions