Use of IOS Uisearchcontroller

Source: Internet
Author: User

-(void) Viewwillappear: (BOOL) animated{
[Super viewwillappear:animated];
[Self settabbarhidden:yes withanimation:yes];
}
-(void) Viewwilldisappear: (BOOL) animated{
[Super viewwilldisappear:animated];
[Self.mySearchController.searchBar Sethidden:yes];
[Self settabbarhidden:no withanimation:yes];
}
-(void) Viewdidload {
[Super Viewdidload];
[Self SetExtraCellLineHidden:self.myTableViewW
];
[Self initcellinfo];
[Self inittableview];
[Self inittitlebar];
[Self initheader];
[Self initsearchbar];
}
-(void) initsearchbar{
Self.mysearchcontroller=[[uisearchcontroller Alloc]initwithsearchresultscontroller:nil];
Self.mysearchcontroller.searchbar.frame=cgrectmake (100, 10, 200, 44);
Self.mytablevieww.tableheaderview=self.mysearchcontroller.searchbar;
[Self.mySearchController.searchBar SizeToFit];
self.mysearchcontroller.searchresultsupdater=self;
Self.mysearchcontroller.dimsbackgroundduringpresentation=no;
Self.mysearchcontroller.hidesnavigationbarduringpresentation=no;
[Email protected] "Enter the Red Rabbit ID or nickname query";
[Self PresentViewController:self.mySearchController animated:yes completion:nil];
}
-(void) initheader{
}
-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{
[TextField Resignfirstresponder];
return YES;
}
-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{
[Self hiddenkeyboard];
}
-(void) hiddenkeyboard{
[Self.mytextfield Resignfirstresponder];
}
-(void) inittitlebar{
[Email protected] "add friends";
}
-(void) initcellinfo{
Nsmutablearray *cellinfoarray=[[nsmutablearray Alloc]init];
Nsmutablearray *nicknamearray=[[nsmutablearray Alloc]init];
Nsmutablearray *idarray=[[nsmutablearray Alloc]init];
cellinfo_t *cellinfo=[self Newcellinfo];
[Email protected] "http://b.hiphotos.baidu.com/image/w%3D310/sign=a0eb5ed6d52a60595210e71b1835342d/ 2fdda3cc7cd98d10f00dbe2e233fb80e7aec90d0.jpg ";
[Email protected] "quack";
[Email protected] "1";
[Cellinfoarray Addobject:cellinfo];
[Nicknamearray AddObject:cellInfo.nickName];
[IDArray AddObject:cellInfo.ID];

Cellinfo=[self Newcellinfo];
[Email protected] "http://c.hiphotos.baidu.com/image/w%3D310/sign=4632f6f379cb0a4685228d385b62f63e/ 902397dda144ad341343938ed2a20cf431ad853e.jpg ";
[Email protected] "ren rongrong";
[Email protected] "2";
[Cellinfoarray Addobject:cellinfo];
[Nicknamearray AddObject:cellInfo.nickName];
[IDArray AddObject:cellInfo.ID];

Cellinfo=[self Newcellinfo];
[Email protected] "http://tao.goulew.com/users/upfile/201403/20140305222531big.jpg";
[Email protected] "Little Ann Lake";
[Email protected] "3";
[Cellinfoarray Addobject:cellinfo];
[Nicknamearray AddObject:cellInfo.nickName];
[IDArray AddObject:cellInfo.ID];

Cellinfo=[self Newcellinfo];
[Email protected] "http://d.hiphotos.baidu.com/image/w%3D310/sign=4276550c5e6034a829e2be80fb1249d9/ D000baa1cd11728b9c43502fcafcc3cec3fd2c55.jpg ";
[Email protected] "road see uneven";
[Email protected] "4";
[Cellinfoarray Addobject:cellinfo];
[Nicknamearray AddObject:cellInfo.nickName];
[IDArray AddObject:cellInfo.ID];

Self.nicknamearray=nicknamearray;
Self.cellinfoarray=cellinfoarray;
Self. Idarray=idarray;
}
-(cellinfo_t *) newcellinfo{
cellinfo_t *info=[cellinfo_t New];
return info;
}
-(void) inittableview{
self.mytablevieww.delegate=self;
self.mytablevieww.datasource=self;
}
-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{
return 1;
}
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{
if (self.mySearchController.active) {
return self.searchList.count;
}else{
return self.cellInfoArray.count;
}
}
-(cellinfo_t *) Getcellinfo: (Nsinteger) row{
return Self.cellinfoarray[row];
}
-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{
return 80;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{
cellinfo_t *cellinfo=[self GetCellInfo:indexPath.row];
Static nsstring *[email protected] "Rraddfriendcell";
Rraddfriendcell *cell=[tableview Dequeuereusablecellwithidentifier:cellid];
if (Cell==nil) {
Cell=[[[nsbundle mainbundle]loadnibnamed:cellid owner:self Options:nil]lastobject];
}
if (self.mySearchController.active) {
Cell.mynickname=self.searchlist[indexpath.row];
}else{
Paimageview *image=[[paimageview alloc]initwithframe:cell.myimage.bounds Backgroundprogresscolor:[uicolor Lightgraycolor] Progresscolor:nil Image:nil];
[Cell.myimage Addsubview:image];
[Image SetImageURL:cellInfo.image];

Cell.mynickname=cellinfo.nickname;
Cell.myid=cellinfo.id;
}
[Cell.myapplyadd settitle:@ "Application to add" forstate:uicontrolstatenormal];
[Cell.myapplyadd addtarget:self Action: @selector (Applyadd) forcontrolevents:uicontroleventtouchupinside];
Cell.selectionstyle=uitableviewcellselectionstylenone;
return cell;
}
-(BOOL) searchbarshouldbeginediting: (Uisearchbar *) searchbar{
return YES;
}
-(void) Updatesearchresultsforsearchcontroller: (Uisearchcontroller *) searchcontroller{
NSString *searchstring = Self.mySearchController.searchBar.text;
Nspredicate *preicate = [Nspredicate predicatewithformat:@ "self contains[c]%@", searchstring];// Create a predicate with Predicatewithformat name as the key path
if (self.searchlist!= nil) {
[Self.searchlist removeallobjects];
}
Filtering data
self.searchlist= [Nsmutablearray Arraywitharray:[self.nicknamearray filteredarrayusingpredicate:preicate];
[Self.mytablevieww Reloaddata];
}
-(void) applyadd{
NSLog (@ "Apply to add");
}
-(void) Setextracelllinehidden: (UITableView *) tableview{
UIView *view =[[UIView alloc]init];
View.backgroundcolor = [Uicolor Clearcolor];
[TableView Settablefooterview:view];
[TableView Settableheaderview:view];
}
-(BOOL) searchbarshouldendediting: (Uisearchbar *) searchbar{
[Searchbar Endediting:yes];
return YES;
}
-(void) searchbarsearchbuttonclicked: (Uisearchbar *) searchbar{
[Searchbar Endediting:yes];
}

Use of IOS Uisearchcontroller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.