Add a row dynamically in TableView of iphone

后端 未结 4 607
花落未央
花落未央 2021-01-05 14:26

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         


        
4条回答
  •  萌比男神i
    2021-01-05 14:49

    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];
    }
    

提交回复
热议问题