UISearBarController
来源:互联网 发布:内存优化级别禁用好吗 编辑:程序博客网 时间:2024/06/03 21:41
iOS8以后出来的,Interface Builder是没有的,只能纯代码。
直接上代码了,蛮简单的
具体你要实现什么,逻辑自己写
//// ViewController.m// UISearBar//// Created by 易云时代 on 2017/8/21.// Copyright © 2017年 笑伟. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchResultsUpdating>@property (nonatomic, strong) UISearchController *serachC;@property (nonatomic, strong) UITableView *table;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WITH, SCREEN_HEIGHT)]; _table.delegate = self; _table.dataSource = self; [self.view addSubview:_table]; _serachC = [[UISearchController alloc]initWithSearchResultsController:nil]; _serachC.searchResultsUpdater = self;//self 为更新结果对象 self.table.tableHeaderView = _serachC.searchBar;}#pragma mark TableViewDelegateAndDataSource-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 50;}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 30;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pp"]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pp"]; } return cell;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10;}-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ return 2;}#pragma mark UISearchBarDelegate-(void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{ [self updateSearchResultsForSearchController:self.serachC];}#pragma mark UISearchResultsUpdating-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{ NSLog(@"%@",_serachC.searchBar.text); [_table reloadData];}
阅读全文
0 0
- UISearBarController
- 使用 Graphviz 生成自动化系统图
- Git Submodule 使用简介
- HDU 4734 数位DP
- 193. Valid Phone Numbers
- JS-上传文件
- UISearBarController
- spark rdd根据key保存进不同的文件夹
- Android进阶#(1/12)Android的构成基石——四大组件_Broadcast
- SQL之decode()函数
- Discuz触屏手机版显示分类信息的修改方法
- Word转换pdf文件之好用的pdf虚拟打印机
- uint8_t / uint16_t / uint32_t /uint64_t 数据类型大总结
- 微信小程序-实战巩固(二)
- CCF 最优灌溉