The table does not display the updated array to return to the cell. When I launch the app I get blank cells. All permissions have been given in the storyboard. I tried the tableView.reloadData() everywhere but can't seem to make it work either. If anyone can explain where Im going wrong that would really help me get better.
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var slider: UISlider!
@IBAction func sliderSelector(_ sender: Any) {
tableGenerate()
}
var arrayTable = [Int]()
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayTable.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style:UITableViewCellStyle.default, reuseIdentifier: "Cell")
cell.textLabel?.text = String(arrayTable[indexPath.row])
tableView.reloadData()
return cell
}
func tableGenerate () {
var tableMultiplier = 1
while tableMultiplier <= 50 {
arrayTable.append(tableMultiplier * Int(slider.value))
tableMultiplier += 1
print(arrayTable)
}
}
tableView.reloadData()insidecellForRowAt? That puts you in in infinite loop, since it will again callcellForRowAt... You only need to calltableView.reloadData()if you change the data source after your table view was set up.tableView.reloadData()from insidesliderSelectoror rather do it from insidetableGenerate()... @Dev0urCode check my answer.arrayTableand calltableView.reloadData()once. That will get the number of rows fromnumberOfRowsInSectionand will ask you for the initialized cell (incellForRowAt). SocellForRowAtshould return theUITableViewCellonly, and do nothing more.