0

By receiving data from an API, i need to compose a dynamic form. This in my head translated to a tableView with cells that have labels and input fields.

The task was completed, the cells were dynamically sized depending on the constraints, all was fine. When some input in some cell changed the following code run:

func valueOfFieldWithIDChanged(id: Int, value: String){
    formFieldsTable.reloadRows(at: [indexPath,indexPath2], with: .none)
}

This updated my row and the new value was displayed properly after formatting etc.

The issue:

When the forms got bigger and spanned more space than a screenful, essentially making the table scrollable a huge issue occurred. When the table was scrolled even a tiny bit, using reloadRows made a glitchy table scroll animation.

The answer to that was essentially: DONT use UITableViewAutomaticDimension in heightForRow if you're gonna use reloadRows.

The thing is, some rows have multiline labels or need to be dynamically sized in some way or another. It seems like i have to calculate this by hand but i dont know how. Unless.. i'm missing something? Truly hope i am

EDIT: Someone mentioned in the comments that there are other ways to updating fields without reloading the rows. This might be a way to go about it but i dont know what those other ways are

Return-1
  • 2,329
  • 3
  • 21
  • 56
  • You need to return a reasonable value for `estimatedHeightForRowAtIndexPath` – Paulw11 Jan 25 '18 at 10:12
  • 1
    Do you really need a varying amount of rows or could you maybe go with a static table view? Also, there are other ways to reload the labels and inputs inside the cell, other than calling reloadRows- like accessing the fields directly. Do you need to cells to resize based on API's content or the users input? – Florensvb Jan 25 '18 at 10:13
  • Other ways like accessing the fields directly huh? That might work,i d like to hear more about it as cells need to mostly be resized by the API content, user input ( at least for now ) is probably not going to affect the sizing. – Return-1 Jan 25 '18 at 10:36
  • Also, you shouldn't need to reload the rows if all that is changing is their size. As long as the constraints adapt then all you may need to do is call `beginUpdates` followed by `endUpdates` – Paulw11 Jan 25 '18 at 10:48
  • Their size isnt really changing. It just needs to calculate them right the first time around, user input doesnt afffect cell size. – Return-1 Jan 25 '18 at 10:51

0 Answers0