Add a row dynamically in TableView of iphone

后端 未结 4 603
花落未央
花落未央 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条回答
  •  轮回少年
    2021-01-05 14:56

    ReloadData can add row in teble view but if you want some animation when row add then you should use these lines of code.

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
            NSMutableArray *tempArray = [[NSMutableArray alloc] init];
            [tempArray addObject:[NSIndexPath indexPathForRow:indexPath.row+1 inSection:0]];
    
            [mainArray insertObject:@"new row" atIndex:indexPath.row+1];
    
            [[self tableView] beginUpdates];
            [[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationFade];
            [[self tableView] endUpdates];
    
    }
    

提交回复
热议问题