快速错误线程 1:EXC_BAD_INSTRUCTION单元格定义



>我在用表格定义单元格时遇到问题。它允许用户搜索一个城市,这是给我带来麻烦的代码。这是视图控制器的完整代码。目标是允许用户在其中列表中搜索城市。

import UIKit
import Foundation
import CoreData
  class SearchBar: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate{
var searchActive : Bool = false
var data: [String] = ["San Francisco","New York","San Jose","Chicago","Los Angeles","Austin","Seattle"]
var filtered: [String] = []
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var checkavailability: UIBarButtonItem!
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var addselected: UIBarButtonItem!
override func viewDidLoad() {
        super.viewDidLoad()
/* Setup delegates */
        tableView.delegate = self
        tableView.dataSource = self
        searchBar.delegate = self
    }
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    searchActive = true
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
searchActive = false
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchActive = false
}
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
searchActive = false
}
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
filtered = data.filter({ (text) -> Bool in
let tmp: NSString = text
let range = tmp.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)
return range.location != NSNotFound
})
if(filtered.count == 0){
    searchActive = false;
}
else {
    searchActive = true;
}
    self.tableView.reloadData()
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()         // Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(searchActive) {
        return filtered.count
}
else {
        return data.count
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell!
if(searchActive == true){
    cell.textLabel?.text = filtered[indexPath.row]
 }
    else {
     cell.textLabel?.text = data[indexPath.row] \ this is where the error comes up 
       }
    return cell
}

}

尝试使用

tableView而不是TableView,即使用小写的"t"。小写表视图是一个类实例,大写表视图是一个类。

最新更新