iOS学习笔记之UITableView之右侧索引

今天做的小demo是实现类似于咱们iPhone上通讯录中的索引,非常简单,大家可以参考一下,有什么不对的地方还请指出!
索引要实现的方法- (NSArray )sectionIndexTitlesForTableView:(UITableView )tableView
这里写图片描述
**

plist文件

**
plist文件
这里写图片描述

#import "ViewController.h"
//标识符
#define MARK @"carList"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong)NSArray *listTeams;
@end

@implementation ViewController

//懒人加载数据
- (NSArray*)listTeams{
    if (_listTeams == nil) {
        _listTeams = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cars_total" ofType:@"plist"]];

    }
    return _listTeams;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark --设置组count
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self listTeams].count;
}
#pragma mark --设置行count
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSArray *rowArray = [self getDiction:section][@"cars"];
    return rowArray.count;
}
#pragma mark 设置cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MARK];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MARK];
    }
    NSArray *rowArray = [self getDiction:indexPath.section][@"cars"];
    NSDictionary *rowDic = rowArray[indexPath.row];
    cell.textLabel.text = rowDic[@"name"];
    cell.imageView.image = [UIImage imageNamed:rowDic[@"icon"]];
    return cell;
}
#pragma mark --设置组标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [self getDiction:section][@"title"];
}
#pragma mark --数据元协议设置索引 
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    //设置索引数组
    NSMutableArray *sectionIndex = [[NSMutableArray alloc] init];
    //从数据中取得索引
    for (NSDictionary *str in self.listTeams) {
        [sectionIndex addObject:str[@"title"]];
    }
    //返回索引
    return sectionIndex;
}

#pragma mark --取出plist中的字典
- (NSDictionary *)getDiction:(NSInteger)section{
    return self.listTeams[section];
}

@end

想点击索引放大,但是索引没有frame之类的,只有color,网上也找了下没找到,有大神知道的还请指教下小白

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值