swift - UISearchResultsUpdating and MPMediaItem -


i'm having problems when searching mpmediaitems. code below present view , filter results. not clear results when search cancelled (subsequent searches add criteria filtered data), change results while removing text (backspacing), or scroll beyond cells presented on screen. how correct mentioned missing behavior? i've tried various things, including setting filteredtabledata , pred nil, i'm missing major here. appreciated. in advance...

class songsviewcontroller: uiviewcontroller, uisearchresultsupdating {  @iboutlet var songstableview: uitableview!  var tabledata = mpmediaquery.songsquery() var song : mpmediaitem?  var tabledatatofilter = mpmediaquery.songsquery() var filteredtabledata : mpmediaitemcollection? var resultsearchcontroller : uisearchcontroller! var pred : mpmediapropertypredicate?  override func viewdidload() {     super.viewdidload()      let nib = uinib(nibname: "songcell", bundle: nil)     songstableview.registernib(nib, forcellreuseidentifier: "cell")      resultsearchcontroller = uisearchcontroller(searchresultscontroller: nil)     resultsearchcontroller.searchresultsupdater = self     resultsearchcontroller.dimsbackgroundduringpresentation = true     resultsearchcontroller.searchbar.sizetofit()     songstableview.tableheaderview = self.resultsearchcontroller.searchbar     songstableview.reloaddata() }  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     if resultsearchcontroller.active {         let count = filteredtabledata!.count         return count     } else {         if let collection = tabledata.collections {         let collectioncount = collection.count         return collection.count             }         }     return 0 }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell     {     let cell : songcell = self.songstableview.dequeuereusablecellwithidentifier("cell") as! songcell      if resultsearchcontroller.active {         song = filteredtabledata!.items[indexpath.row]         let songname = song!.valueforproperty(mpmediaitempropertytitle) as! nsstring         cell.songtitlelabel.text = songname string     } else {      song = tabledata.items![indexpath.row]      if song!.valueforproperty(mpmediaitempropertytitle) == nil {      cell.songtitlelabel.text = "song title blank" string      } else {      let songname = song!.valueforproperty(mpmediaitempropertytitle) as! nsstring      cell.songtitlelabel.text = songname string      }  func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) {     pred = mpmediapropertypredicate(value: searchcontroller.searchbar.text!, forproperty: mpmediaitempropertytitle, comparisontype: mpmediapredicatecomparison.contains)     tabledatatofilter.addfilterpredicate(pred!)     filteredtabledata = mpmediaitemcollection(items: tabledatatofilter.items!)     self.songstableview.reloaddata() } 


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -