Friday 15 February 2013

uitableview - UISearchController in a UIViewController -



uitableview - UISearchController in a UIViewController -

i'm looking create similar functionality apple's maps application in swift. there anyway integrate uisearchcontroller in regular view (i.e.: not uitableview). dropping 1 in through storyboard results in crash after clicking within connected searchbar. or there way can accomplish outcome uitableview?

i added search bar , search display controller in view controller in storyboard. view controller contains search bar , search display controller , not have it's own tableview. when add together search bar in view controller, sets view controller it's delegate automatically.

now search bar , search display controller has table view of uses display search results when click within box , start typing. table view expects view controller provide implementations of numberofrowsinsection , cellforrowatindexpath functions display info properly.

when run project without these , tap within search bar, next error:-

tableview:numberofrowsinsection:]: unrecognized selector sent instance 0x7fbf63449660 *** terminating app due uncaught exception 'nsinvalidargumentexception'

if see, error @ numberofrowsinsection method.

change view controller definition from

class viewcontroller: uiviewcontroller

to

class viewcontroller: uiviewcontroller,uitableviewdelegate,uitableviewdatasource

and implement required methods are:-

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { homecoming uitableviewcell() } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { homecoming 0 }

i have added default homecoming values in above methods.

now if filter out info source in searchviewdelegate methods , set number of rows , cell info in above 2 methods properly, should work.

hope helps!

uitableview swift uisearchcontroller

No comments:

Post a Comment