我有一个包含搜索栏的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;
}
} 请帮助!
答案 0 :(得分:0)
我解决了它,我只改变为true,搜索活动如下:func searchBarTextDidEndEditing(searchBar:UISearchBar){ searchActive = true; }