views:

911

answers:

3

Hi all,

I need to add a new row in the tableview when i select a row in the table.

Am i suppose to use the following method???

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

What shoud i write inside the method to add a new row.?

Please do help me,

Thanks in advance Shibin.

+1  A: 

If you are filling your table from an array, you can just add an element to your array and call [myTable reloadData]

Morion
no, i am not loading the new row data from an array. what i need is to add a new row when i select any particular row in the table. it just get appended to my existing table.
Shibin Moideen
Hmm. And what is the source for your table view content?
Morion
You could just change the number of items returned by numberOfRowsInSection and update the data returned by cellForRowAtIndexPath appropriately. Then call reloadData as above.
Epsilon Prime
+2  A: 

When I add a row dynamically, I use insertRowsAtIndexPaths: here is an example function

- (void) allServersFound {
    // called from delegate when bonjourservices has listings of machines:
    bonjourMachines = [bonjourService foundServers]; // NSArray of machine names;

    NSMutableArray *tempArray = [[NSMutableArray alloc] init];

    int i = 0;
    for (NSArray *count in bonjourMachines) {
        [tempArray addObject:[NSIndexPath indexPathForRow:i++ inSection:0]];
    }

    [[self tableView] beginUpdates];
    [[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone];
    [[self tableView] endUpdates];

    [tempArray release];
}
Ryna
A: 

reload data is nice and simple, but does not animate as far as I can tell...

dhvidding