当使用UISearchBar时,searchResultsTableView中显示“无结果”文本,我们可以更改“无结果”文本吗?
答案 0 :(得分:1)
In the first method, we are only changing the appearance of search bar when a user taps on search bar. Refer the first two images to find the difference. The main code will be written now:
take Label and set Text NO Resluts and Set Hidden YES In View DidLoad.
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[tableData removeAllObjects];
// remove all data that belongs to previous search
if([searchText isEqualToString:@""] || searchText==nil){
[tblview reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in dataSource)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
//NSRange r = [name rangeOfString:searchText];
NSRange r=[name rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(r.location != NSNotFound)
{
if(r.location== 0)//that is we are checking only the start of the names.
{
[tableData addObject:name];
}
}
counter++;
[pool release];
}
if([tableData count]==0)
{
label.hidden=NO;
}
[tblview reloadData];
}