swift - Search functionality in iOS 8 -
http://www.ioscreator.com/tutorials/add-search-table-view-tutorial-ios8-swift
i following tutorial. lot of red errors due using named tuple, not simple array in tutorial. need tuple, can provide right code problem?
i have code:
var mydata = [data]() // adding data array var newdata = data(category: "lorem", name: "ipsum") mydata.append(newdata) i first error here:
controller.searchresultsupdater = self any help?
my solution. , should add uisearchresultsupdating, uisearchcontrollerdelegate, uisearchbardelegate
var dataforsearch: [music]? = nil var searchcontroller: uisearchcontroller! var searchpredicate: nspredicate! func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) { self.dataforsearch?.removeall(keepcapacity: false) var searchtext = searchcontroller.searchbar.text if searchcontroller.active == true { searchpredicate = nspredicate(format: "namesong contains[c] %@", searchtext) dataforsearch = self.fetchedresultscontroller?.fetchedobjects?.filter() { return self.searchpredicate.evaluatewithobject($0) } as! [music]? } self.tableview.reloaddata() } func searchbar(searchbar: uisearchbar, selectedscopebuttonindexdidchange selectedscope: int) { updatesearchresultsforsearchcontroller(searchcontroller) } override func viewdidload() { super.viewdidload() self.tableview.delegate = self searchcontroller = ({ var controllersearch = uisearchcontroller(searchresultscontroller: nil) controllersearch.delegate = self controllersearch.searchbar.delegate = self controllersearch.definespresentationcontext = false // default false controllersearch.hidesnavigationbarduringpresentation = true controllersearch.searchbar.sizetofit() controllersearch.searchresultsupdater = self self.tableview.tableheaderview = controllersearch.searchbar return controllersearch })() self.tableview.reloaddata() }
Comments
Post a Comment