Thanks a lot for the reply Claude31 and for clarifying some aspects that were not very obvious for me.
I have tried implementing something along your line but I still have to press twice on my the SegmentedControl button to set the value of the button when I use myTableView.reloadRows(at: [index], with: .none) in func segmentControlSelected. Even so, the appeareance of the UISlider does not change.
If I comment out reloadRows(at:with:), the SegmentedControl buttons set their values on the first click. Do you know why this happens?
My cellForRowAt func contains the following:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: K.cellNibName, for: indexPath) as! AccountHoldingsCell
//Cell Delegate setup
cell.delegate = self
cell.cellIndexPath = indexPath
....
cell.cellSlider.isEnabled = myData[indexPath.row]
//Activity indicator
self.activityIndicatorView.stopAnimating()
return cell
}
Inside ViewControl class I have:
class ViewController: UIViewController {
....
var mergedBalance = ViewBalanceModel()
var tempMergedBalance = ViewBalanceModel()
var nbOfTableItems = 0
var myData : [Bool] = []
...
}
myData is initialized inside a custom protocol that decodes API data and constructs a model in func
extension ViewController: ViewBalanceProtocol {
func didUpdateBalanceTable(from manager: Manager, with accData: ViewBalanceModel) {
.... //Get Api data into tempMergedBalance struct
nbOfTableItems = tempMergedBalance.arrayOfItems.count
myData = Array(repeating: false, count: nbOfTableItems) //Array setting initial values as False for UISlider
DispatchQueue.main.async {
self.mergedBalance = self.tempMergedBalance
self.myTableView.refreshControl?.endRefreshing()
self.myTableView.reloadData()
}
}
And of course:
extension ViewController: AccountCellDelegate {
func segmentControlSelected(cell: UITableViewCell, at index: IndexPath, segmentValue: Int, slider: UISlider) {
myData[index.row] = (segmentValue != 0)
myTableView.reloadRows(at: [index], with: .none)
}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: