Fatal error: array index out of range in uitableview back to previous swift controller

I have UITableview

one containing a search string, everything works fine with my filter. When I click on a cell to pass values ​​to another UIViewController

and open it at the same time UIViewController

everything works fine. But my problem is that when I press the back button to return to UITableViewController

, I get this error:

Array index out of range

From this line of code:

cell.textLabel?.text = filtered[indexPath.row]

      

Here's all 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


source to share


1 answer


I solved this, I only changed true to make the search active like this: func searchBarTextDidEndEditing (searchBar: UISearchBar) {searchActive = true; }



0


source







All Articles