How to dynamically add rows to a specific UITableView section?

后端 未结 5 1644
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:04

    Swift 3 version

    // Adding new item to your data source
    dataSource.append(item)
    // Appending new item to table view
    yourTableView.beginUpdates()
    // Creating indexpath for the new item
    let indexPath = IndexPath(row: dataSource.count - 1, section: yourSection)
    // Inserting new row, automatic will let iOS to use appropriate animation 
    yourTableView.insertRows(at: [indexPath], with: .automatic)
    yourTableView.endUpdates()
    

提交回复
热议问题