UISearchBar * search=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
search.showsCancelButton=YES;//显示取消按钮
search.autocapitalizationType=UITextAutocorrectionTypeNo;//大小写
self.searchBar=search;
self.tableView.tableHeaderView=search;//搜索栏显示在表格顶端
UISearchDisplayController * display=[[UISearchDisplayController alloc] initWithSearchBar:search contentsController:self];
display.searchResultsDataSource=self;
display.searchResultsDelegate=self;
//[display release];
[search release];
--------------------------------------------------------
//输入的搜索内容
NSPredicate * predicate=[NSPredicate predicateWithFormat:@"SELF contains[cd] %@",self.searchBar.text];//cd不区分大小写 自身是否包含搜索栏的内容
self.filterArr=[self.colors.allKeyssortedArrayUsingSelector:@selector(compare:)];
self.filterArr=[self.filterArrfilteredArrayUsingPredicate:predicate];//筛选后的数组