First make a fake data
Data=[nsarray arraywithobjects:@ "W", @ "WWE", @ "Wwweer", @ "Eee", @ "fff", @ "FFFQ", nil];
Define a bool value that is Isfind initial value set to 0
Isfind=no, which is not a search state
Set the different number of rows for the search and non-search states
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{
if (Isfind==no) {
return data.count;
}
Else
{
return finddata.count;
}
}
Set the cell
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{
Static nsstring *[email protected] "cellid";
UITableViewCell *cell=[tableview Dequeuereusablecellwithidentifier:cellid];
if (Cell==nil) {
Cell=[[uitableviewcell Alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:cellid];
}
if (Isfind==yes) {
Cell.textlabel.text=[finddata ObjectAtIndex:indexPath.row];
}
return cell;
}
iOS Learning Note 12-uisearchbar