xcode - Swift error thread 1: EXC_BAD_INSTRUCTION cell definition -
i having trouble defining cell table. allows user search city code giving me trouble. entire code view controller. goal allow user search city in list of them.
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 resources can 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] \\ error comes } return cell }
}
try tableview instead of tableview, i.e. lowercase 't'. lowercase tableview class instance, uppercase tableview class.
Comments
Post a Comment