views:

328

answers:

1

Hi, everyone.

I am working on an iPhone application but something strange happen. I think I can ask you for advice.

I implemented a TableView and a custom view as a create new object form. I make the custom view slide up when user tab 'Add' button in the tool bar in TableView like the code below:

- (void)slide_up_form:(id)sender {

    CustomViewController *controller = [[CustomViewController alloc] init];

    // Assign this controller to use add_entity: message to TableView.
    controller.parent = self;

    [self presentModalViewController:controller animated:TRUE];
}

// To update TableView presentation.
-(void)add_block:(Block *)newBlock
{
 [blockArray insertObject:newBlock atIndex:0];
 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
 [self.tblCameraList insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                              withRowAnimation:UITableViewRowAnimationNone];

        [self.tblCameraList scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
                         atScrollPosition:UITableViewScrollPositionTop animated:YES];

 }

and in custom view, user fill the form and tab 'Save' button. So I did save the entity to Core data. and need to update the TableView with new object, so I code following statement in custom view:

@synthesize parent;

- (void)save_block:(id)sender {
// save entity.

[self.parent add_block:newBlock];

// Slide down the custom view and show the TableView.
[[self parentViewController] dismissModalViewControllerAnimated:TRUE];
}

I have tested this already in simulator and iPhone. when user tab 'Save' button, the application saved the new entity, but it doesn't update TableView with new entry.

Could you give your advice to solve this problem?

A: 

Take a look at the reloadData method on UITableView - it tells the view to redo everything that causes it to display cells, from the data fetches on up. Assuming your table view's data source uses your Core Data store to provide its data, your table should then contain the new object.

Alternately, you could have the popup controller add the new object to the table itself - give the popup controller a pointer to the table in the main controller, and use any of UITableView's methods to insert objects. Just make sure that what you're inserting in the table is consistent with what you're inserting into the Core Data store. (You can see some of Apple's Core Data projects, like CoreDataRecipes, for more on this.)

Tim