I am Getting
fatal error: Index out of range" and "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" at line "cell.textLabel?.text = String(arrayTable[indexPath.row])
When I test my function in playground it works as expected. My array get populated. So, I don't understand why Xcode won't find any value in my array.
any idea?
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var slider: UISlider!
@IBAction func sliderSelector(_ sender: Any) {
arrayTable = [Int]()
tableGenerate()
}
var arrayTable = [Int]()
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style:UITableViewCellStyle.default, reuseIdentifier: "Cell")
cell.textLabel?.text = String(arrayTable[indexPath.row])
return cell
}
func tableGenerate () {
var tableMultiplier = 1
while tableMultiplier <= 50 {
arrayTable.append(tableMultiplier * Int(slider.value))
tableMultiplier += 1
}
}
fatal error: Index out of rangeMeansnumberOfRowsInSectionnot sync withcellForRowAtIndexPathwith your array count.