在没有搜索到项目的情况下,我们可以更改UISearchBar中的“无结果”文本吗?

时间:2011-08-24 03:43:09

标签: iphone uisearchbar

当使用UISearchBar时,searchResultsTableView中显示“无结果”文本,我们可以更改“无结果”文本吗?

enter image description here

1 个答案:

答案 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];


}