views:

186

answers:

1

This is related to my last question.

I have an application that I created from the "Navigation-based application" template in Xcode. (I have a UINavigationController with a UITableViewController subclass named RootViewController.)

The table shows a list of strings the user can interact with. The nav bar has the standard Edit/Done button on the left, and a Plus-sign button on the right. I would like to slide a view loaded from a .xib file from under the nav bar when the user touches the plus button.

I attempted to implement it by doing the following:

NSArray *xibContents = [[NSBundle mainBundle] loadNibNamed:@"NewNameView" owner:self options:nil];
UIView *view = [xibContents objectAtIndex:0];
[self.view addSubview:view];
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y - 44, view.frame.size.width, view.frame.size.height);
[UIView beginAnimations:@"openAdd" context:nil];
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + 44, view.frame.size.width, view.frame.size.height);
[UIView commitAnimations];

(The height of the view is 44 pixels.) This animates the view sliding down, but it covers the first table cell. I'd like for the table view to slide down as well.

+1  A: 

The best way to do this to use directly UITableView methods.

//Update your data model with the new row

[self.tableView beginUpdates];

NSArray* indexPaths = [[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
[indexPaths release];

[self.tableView endUpdates];

Your new row will looks like it would come from under the Navigation bar.

For more info on batch insert/deleting of row and sections.

gcamp