Adding Insert Row in tableView

Posted by user333624 on Stack Overflow See other posts from Stack Overflow or by user333624
Published on 2010-05-05T16:00:02Z Indexed on 2010/05/07 20:48 UTC
Read the original article Hit count: 203

Filed under:
|
|

Hello everyone, I have a tableView that loads its data directly from a Core Data table with a NSFetchedResultsController. I'm not using an intermediate NSMutableArray to store the objects from the fetch results;

I basically implemented inside my UITableViewController the protocol method numberOfRowsInSection and it returns the numberOfObjects inside a NSFetchedResultsSectionInfo.

id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];

and then I configure the cell content by implementing configureCell:atIndexPath and retrieving object info from the fetchedResultController but right now I have a generic configuration for any object (to avoid complications)

cell.textLabel.text = @"categoria";

I also have a NavigationBar with a custom edit button at the right that loads my own selector called customSetEditing. What I'm trying to accomplish is to load an "Insert Cell" at the beginning of the tableView so when I tap it, it creates a new record. This last part is easy to implement the problem is that I dont's seem to be able to load the insert row or any row when I tap on the navigation bar edit button.

this is the code for my customSetEditing:

- (void) customSetEditing {
            [super setEditing:YES animated:YES];
            [self.tableView setEditing:YES animated:YES];
            [[self tableView] beginUpdates];
            //[[self tableView] beginUpdates];
            UIBarButtonItem *customDoneButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(customDone)];
            [self.navigationItem.rightBarButtonItem release];
            self.navigationItem.rightBarButtonItem = customDoneButtonItem;
            //[categoriasArray insertObject:[NSNull null] atIndex:0];
            NSMutableArray *indexPaths = [[NSMutableArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:0],nil ];
            [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
            //[indexPaths release];
            [self.tableView reloadData];}

Before adding the:[self.tableView reloadData]; I was getting an out of bounds error plus a program crash and although the program is not crashing it is not loading anything.

I have seen many examples of similar situations in stackoverflow (by the way is an excellent forum with very helpful and nice people) none of the examples seems to work for me.

Any ideas?

© Stack Overflow or respective owner

Related posts about uitableview

Related posts about core-data