It seems like you are telling the table there will be more rows than you actually want to display and then deleting them after the fact.
Instead you should be checking if the elements in the array meet the criteria in (or before) numberOfRowsInSection
and putting them into a different array that will actually be displayed so that the table knows how many rows will actually be displayed. Then in cellForRowAtIndexPath
just use the newly create array that has the data that will actually be displayed.
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
self.displayArray = []
for (index, number) in self.locations {
if number <= 5 {
self.displayArray.Add(self.locations[index])
}
}
return self.displayArray.Count
}
I'm assuming your error has something to do with you trying to update the table in a method that is first trying to create it. You're trying to update something that hasn't fully been created.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…