For a display screen, I’ve used a UITableviewController with a static cell. The entire UIComponents reminiscent of label, picture, buttons are outlined inside this static cell.
Now, I have to have a dynamic tableview inside this cell. Its top just isn’t fastened. It has to range based mostly on the variety of cells it comprises.
this is how the delegate and datasource appears like
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
if tableView.tag == 2 {
return 3
}
return tremendous.tableView(tableView, numberOfRowsInSection: part)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView.tag == 2 {
let cell = (tableView.dequeueReusableCell(withIdentifier: Fixed.ReuseIdentifiers.offersViewCell) as? OffersTableViewCell)!
return cell
}
return tremendous.tableView(tableView, cellForRowAt: indexPath)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView.tag == 2 {
// Do one thing when a dynamic row is chosen
} else {
tremendous.tableView(tableView, didSelectRowAt: indexPath)
}
}
After I run the applying and navigate to this display screen, it fails with an error “Terminating app because of uncaught exception ‘NSRangeException’, cause: ‘*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 past bounds [0 .. 0]'”
learn how to differentiate the datasource/delegate strategies for this static tableview and dynamic tableview.
Earlier when there was no dynamic tableview, I did not should implement these strategies however now I consider that is the place the issue lies. Any solutions or concepts?
I additionally tried, the Dynamic Tableview with a set top. Nonetheless it was failing with the identical error. So, learn how to implement this accurately. I could make this tableview resizable later