在navigationItem中添加搜索栏

    给navigationItem中添加个搜索栏,效果和大部分程序一样。代码如下:

 

    UISearchBar *searchBar = [[UISearchBaralloc] initWithFrame:CGRectMake(0, 0, 200, 28)];

    searchBar.backgroundImage = [UIImageimageNamed:@"btu_search"];

    searchBar.placeholder = @"搜索";

    searchBar.delegate = self;

    

    UIBarButtonItem *searchButton = [[UIBarButtonItemalloc]initWithCustomView:searchBar];

 

    self.navigationItem.rightBarButtonItems = [NSArrayarrayWithObject:searchButton];

 

    最后在- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 方法里面写搜索方法就可以了。比较简单,做个记录。

 

展开阅读全文

没有更多推荐了,返回首页