1

我有一个UITableview包含搜索栏的搜索栏,我的过滤器一切正常。当我单击一个单元格将值传递给另一个单元格UIViewController并同时打开它UIViewController时,一切仍然正常。但我的问题是,当我单击后退按钮返回 时UITableViewController,我收到此错误:

数组索引超出范围

从这行代码:

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

这是我的所有代码:

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;

}

} 请帮忙!

4

1 回答 1

0

我解决了它,我只将搜索活动更改为 true,如下所示: func searchBarTextDidEndEditing(searchBar: UISearchBar) { searchActive = true; }

于 2015-05-01T20:24:11.437 回答