6.10 UITableView

1,创建TableView

@property(strong, nonatomic) UITableView               *tableView;         //表格视图

//1,创建tableview
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                  style:UITableViewStylePlain];
    //2,设置属性

    self.tableView.dataSource = self;                                        //2.1 设置数据源
    self.tableView.rowHeight = 50;                                           //2.2 设置固定行高
    self.tableView.sectionIndexBackgroundColor = [UIColor grayColor];        //2.3 修改右侧指示栏背景颜色
    self.tableView.sectionIndexTrackingBackgroundColor = [UIColor lightGrayColor]; //2.4 修改右侧指示栏背景颜色(点击时)
    self.tableView.sectionIndexColor = [UIColor blackColor];                 //2.5 修改右侧指示栏标题颜色
    self.tableView.delegate = self;                                          //2.6 设置代理

    //3,添加到父视图
    [self.view addSubview:self.tableView];

2,ResultTableViewController创建

//4,创建收索控制器

    ResultTableViewController *resultVC = [[ResultTableViewController alloc] init];                 //4.1 创建结果控制器
    self.searchController = [[UISearchController alloc]initWithSearchResultsController:resultVC];   //4.2 创建收索控制器


    [self.searchController.searchBar sizeToFit];                                      //4.3 和tabview头部进行关联
    self.tableView.tableHeaderView = self.searchController.searchBar;                 //4.4 自适应大小
    self.definesPresentationContext = YES;                                            //4.5 找到searchController正确的位置
    self.searchController.dimsBackgroundDuringPresentation = NO;                      //4.6 呈现时取消背景
    self.searchController.searchResultsUpdater = self;                                //4.7 设置searchResultsUpdater

3,UITabkeViewDelegate

#pragma mark - UITabkeViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

// 配置每一行cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

// 配置区段的头部显示文本
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return self.keys[section];
}

// 配置右侧指示栏标题列表
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSLog(@"%@",_keys);
    return self.keys;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值