在iphone的TableView中动态添加一行

sma*_*str 6 iphone row tableview

当我在表格中选择一行时,我需要在tableview中添加一个新行.

我想使用以下方法???

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Run Code Online (Sandbox Code Playgroud)

我在方法中写了什么来添加新行.

请帮帮我

提前谢谢Shibin.

小智 13

当我动态添加一行时,我使用insertRowsAtIndexPaths:这是一个示例函数

- (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];
}
Run Code Online (Sandbox Code Playgroud)


Mor*_*ion 1

如果您要从数组填充表,则只需向数组添加一个元素并调用[myTable reloadData]