How to dynamically add rows to a specific UITableView section?

后端 未结 5 1647
Happy的楠姐
Happy的楠姐 2020-12-06 13:23

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 actio

5条回答
  •  不思量自难忘°
    2020-12-06 14:15

    You can use the same method insertRowAtIndexPath like

     // Add the items into your datasource object first. Other wise you will end up with error
     // Manage the number of items in section. Then do
    
     NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:0 inSection:1];
     NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:1 inSection:1];
    [self.tableView insertRowsAtIndexPaths:@[indexPath1,indexPath2] withRowAnimation:UITableViewRowAnimationTop];
    

    This will insert two rows to the section1. Remember before doing this you have manage your datasource object.

提交回复
热议问题