I know that there have been a lot of questions asked on this error but I went through all of them and none of them helped. I'm calling the function addCell() from my main class and the code below is what I have in my TableViewControllerClass. I definitely have my requestIdentifier "cell" linked up in my .storyboard, and the arrays "locations" and "times" are definitely not empty because I print them when the error occurs, so the problem has to be with my "table" variable, that is also properly linked to the table view, but is evidently nil for some reason. Any suggestions?
func addCell(){
//update to insertion sort
currLocation = addLocation
if (locations == [""] && times == [0]) {
self.locations.removeAll()
self.times.removeAll()
}
if !(locations.isEmpty){
if locations[locations.count-1] != currLocation {
var count = 0
var neverVisited = true
for location in locations{
if location == currLocation{
neverVisited = false
times[count] += addTime
count++
}
}
if neverVisited {
locations.append(currLocation)
times.append(addTime)
}
} else {
times[times.count-1] = addTime
}
} else {
locations.append(currLocation)
times.append(addTime)
}
print(locations) //not empty
print(times) //not empty
table.reloadData() //crashes here
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = locations[indexPath.row] + ", \(times[indexPath.row])"
}
return cell
}