问题
I have a UITableview
that contains a search bar, with my filter everything works perfectly. When I click on a cell to pass values to another UIViewController
and open the UIViewController
at the same time, everything still works perfectly. But my problem is when I click to back button to get back to the the UITableViewController
, I get this error:
Array index out of range
From this line of code :
cell.textLabel?.text = filtered[indexPath.row]
Here's all of my code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell;
if(searchActive){
cell.textLabel?.text = filtered[indexPath.row]
} else {
var aaa = posts1.objectAtIndex(indexPath.row).valueForKey("speedKPH") as NSString
let speeddouble = NSString(string: aaa).intValue
var aa = String(speeddouble)
var bb = posts1.objectAtIndex(indexPath.row).valueForKey("timestamp") as NSString
var now = (NSDate(timeIntervalSince1970:(bb as NSString).doubleValue))
var formatter = NSDateFormatter()
formatter.dateFormat = "dd-MM-yyyy' 'HH:mm' '"
formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
cell.textLabel?.text = posts.objectAtIndex(indexPath.row).valueForKey("description") as NSString + "\n"+"Velocidad : " + aa+" KM/H / Ult. Act. :" + formatter.stringFromDate(now)
cell.detailTextLabel?.text = posts.objectAtIndex(indexPath.row).valueForKey("deviceID") as NSString
}
SwiftSpinner.hide()
return cell;
}
} Please Help!
回答1:
I resolved it, i only change to true the search active like this: func searchBarTextDidEndEditing(searchBar: UISearchBar) { searchActive = true; }
来源:https://stackoverflow.com/questions/29972336/fatal-error-array-index-out-of-range-in-uitableview-on-back-to-previous-control