如何动态地将行添加到特定的UITableView部分?

vmf*_*sta 6 objective-c uitableview ios

我是一名新的IOS程序员,我遇到了问题.

我有一个UITableView有2个部分,一个是静态的,另一个是动态的.

在特定的操作中,我需要在运行时为第二部分添加新行.

我知道如何管理UITableView,但不是特定的部分

请问你能帮帮我吗?

最好的问候你们

Akh*_*jtr 12

你可以使用insertRowsAtIndexPaths:方法UITableView

//Update data source with the object that you need to add
[tableDataSource addObject:newObject];

NSInteger row = //specify a row where you need to add new row
NSInteger section = //specify the section where the new row to be added, 
//section = 1 here since you need to add row at second section

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)