vmfesta vmfesta - 1 year ago 87
iOS Question

How to dynamically add rows to a specific UITableView section?

I am a new IOS Programmer, and i am having a issue.

I have a UITableView with 2 sections, one then is static, and another one is dynamical.

In specific actions i need to add new rows for the second section in runtime..

I know how to manage a UITableView , but not a specific section

Could you help me please?

Best Regards you all

Answer Source

You can use insertRowsAtIndexPaths: method of 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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download