UISearchDisplayController UISearchBar
分组表+本地搜索 UISearchDisplayController UISearchBar 的使用
效果图
@interface CityListViewController :UIViewController<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
@property (nonatomic, retain) UITableView*mTableView;
@property (nonatomic, retain) NSArray*dataList;
@property (nonatomic, retain) NSArray*searchData;
@property (nonatomic, retain)NSMutableArray *allCitys;
@property (nonatomic, retain) UISearchBar*mSearchBar;
@property (nonatomic, retain)UISearchDisplayController *searchController;
@end
#import"CityListViewController.h"
#import "AppDelegate.h"
- (void)viewDidLoad
{
//初始化分组表
self.mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 88,320, 480) style:UITableViewStyleGrouped];
self.mTableView.delegate = self;
self.mTableView.dataSource = self;
[self.mTableViewsetContentSize:CGSizeMake(320, 3000)];
//初始化搜索条
self.mSearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 44, 320, 44)];
[self.mSearchBarsetBackgroundImage:[UIImage imageNamed:@"nav_bg.png"]];
[self.mSearchBar setPlaceholder:@"搜索城市"];
self.mSearchBar.delegate = self;
[self.mSearchBar sizeToFit];
//初始化UISearchDisplayController
self.searchController =[[UISearchDisplayController alloc] initWithSearchBar:self.mSearchBarcontentsController:self];
self.searchController.searchResultsDelegate= self;
self.searchController.searchResultsDataSource = self;
self.searchController.delegate = self;
//解析数据源文件
NSString *path = [[NSBundle mainBundle]pathForResource:@"Provineces" ofType:@"plist"];
self.dataList = [NSMutableArrayarrayWithContentsOfFile:path];
//确定每个分组的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if([tableViewisEqual:self.searchController.searchResultsTableView]){
相关新闻>>
- 发表评论
-
- 最新评论 更多>>