ios - UINavigationController with UISearchBar and UISearchDisplayController -
ios - UINavigationController with UISearchBar and UISearchDisplayController -
heres few photos started:
this have main view:
then when user selects uisearchbar, happens:
instead of sec photo, view alter this:
here code far:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. /* self.searchview = [[usersearchview alloc] initwithframe:self.view.frame]; self.searchview.searchresults.delegate = self; self.searchview.searchresults.datasource = self; [self.view addsubview:self.searchview]; */ self.maintableview = [[uitableview alloc] initwithframe:self.view.frame style:uitableviewstyleplain]; [self.maintableview setdelegate:self]; [self.maintableview setdatasource:self]; [self.maintableview setshowshorizontalscrollindicator:no]; [self.maintableview setshowsverticalscrollindicator:no]; [self.view addsubview:self.maintableview]; self.searchbar = [[uisearchbar alloc] init]; [self.searchbar setbarstyle:uibarstyleblacktranslucent]; [self.searchbar setautocorrectiontype:uitextautocorrectiontypeno]; [self.searchbar setautocapitalizationtype:uitextautocapitalizationtypenone]; self.searchcon = [[uisearchdisplaycontroller alloc] initwithsearchbar:self.searchbar contentscontroller:self]; [self.searchcon setdelegate:self]; [self.searchcon setsearchresultsdatasource:self]; [self.searchcon setsearchresultsdelegate:self]; self.navigationitem.titleview = self.searchcon.searchbar; /* generates result want not want search * bar in tableviews header, rather in uinavigationcontroller's * uinavigationbar. */ //self.maintableview.tableheaderview = self.searchbar; [self.view setbackgroundcolor:[uicolor whitecolor]]; } #pragma mark - #pragma mark - uisearchdisplaycontroller delegate - (bool)searchdisplaycontroller:(uisearchdisplaycontroller *)controller shouldreloadtableforsearchstring:(nsstring *)searchstring { if ([searchstring isequaltostring:@""]) homecoming no; pfquery *query = [pfuser query]; [query wherekey:@"username" containsstring:searchstring]; [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (!error) { self.array = [nsmutablearray arraywitharray:objects]; [self.searchdisplaycontroller.searchresultstableview reloaddata]; [self.maintableview reloaddata]; } else { [[[uialertview alloc] initwithtitle:@"failed search" message:[nsstring stringwithformat:@"%@", [error userinfo]] delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil] show]; } }]; homecoming yes; } - (void)searchdisplaycontrollerdidbeginsearch:(uisearchdisplaycontroller *)controller { [controller.searchbar setshowscancelbutton:yes animated:yes]; nslog(@"%@", controller); } - (void)searchdisplaycontrollerdidendsearch:(uisearchdisplaycontroller *)controller { [controller.searchbar setshowscancelbutton:no animated:yes]; nslog(@"%@", controller); } #pragma mark - #pragma mark - uitableview delegate & datasource - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming [self.array count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:nil]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:nil]; } [cell.textlabel settext:[[self.array objectatindex:[indexpath row]] objectforkey:@"username"]]; homecoming cell; } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { profileviewcontroller *profile = [[profileviewcontroller alloc] init]; [profile setprofileuser:[self.array objectatindex:[indexpath row]]]; [self.navigationcontroller pushviewcontroller:profile animated:yes]; }
i kinda lost on how create destination view work. viewing facebook application reproduce, way search bars implemented.
in addition, i'm using parse framework. lot of info beingness populated tableview abstracted code.
try this... in .h file
@interface yourtviewcontroller : uiviewcontroller <uitableviewdatasource,uitableviewdelegate,uisearchbardelegate,uisearchdisplaydelegate> @property (nonatomic,strong) uisearchdisplaycontroller* searchdisplaycontroller; @property (weak, nonatomic) iboutlet uisearchbar *mysearchbar; //connect iboutlet serach bar in storyboard or xib.
in viewdidload
- (void)viewdidload { [super viewdidload]; self.mysearchbar.delegate=self; self.searchdisplaycontroller = [[uisearchdisplaycontroller alloc] initwithsearchbar:self.mysearchbar contentscontroller:self]; self.searchdisplaycontroller.delegate = self; self.searchdisplaycontroller.searchresultsdatasource = self; self.searchdisplaycontroller.searchresultsdelegate = self; // additional code here // }
now implement delegate methods of searchdisplaycontroller.
ios objective-c uinavigationbar uisearchbar uisearchdisplaycontroller
Comments
Post a Comment