ios - headerview from previous view takes up space in UISearchController search results -
i have simple tableview, dailyattendancecontroller, searchbar. searchbar added in viewdidload. view tableview here.
import uikit class oldcellstableviewcontroller: uitableviewcontroller { let data = ["a", "b", "c"] var searchcontroller:uisearchcontroller! let resultscontroller = searchresultsupdater() override func viewdidload() { super.viewdidload() resultscontroller.data = data searchcontroller = uisearchcontroller(searchresultscontroller: resultscontroller) let searchbar = self.searchcontroller.searchbar searchbar.scopebuttontitles = ["all", "short", "long"] searchbar.placeholder = "search student" searchbar.sizetofit() self.tableview.tableheaderview = searchbar self.searchcontroller.searchresultsupdater = resultscontroller } // mark: - table view data source override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return data.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = uitableviewcell() let info = data[indexpath.row] cell.textlabel?.text = info return cell } }
i created class, searchresultscontroller, handle search. searching works fine, space allocated dailyattendancecontroller's header. view searchresultscontroller here
how remove this?
code searchresultscontroller:
import uikit import coredata class searchresultscontroller: uitableviewcontroller, uisearchresultsupdating { var data:[string] = [] var filtereddata:[string] = [] override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() } // mark: - table view data source override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return filtereddata.count } func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) { filtereddata.removeall(keepcapacity: true) let searchstring = searchcontroller.searchbar.text info in data { if (info.uppercasestring.rangeofstring(searchstring.uppercasestring) != nil) { filtereddata.append(info) } } tableview.reloaddata() } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = uitableviewcell() cell.textlabel?.text = filtereddata[indexpath.row] return cell } }
Comments
Post a Comment