【IOS】 TableView and sectionIndex 的使用


1. TableView的基本概念以及使用:

主要记住 :cell的初始化
static  String * NSString  = @"Cell" ;
   //这里不要用 [tableViewdequeueReusableCellWithIdentifier:CellIdentifier indexPath:]
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier :CellIdentifier];
    if (cell == nil ) {
        cell = [[
UITableViewCell alloc ] initWithStyle : UITableViewCellStyleSubtitle reuseIdentifier :CellIdentifier];
    }cell.textLabel.text = [animals objectAtIndex:indexPath.row];

2. 有时候由于TableView的height不够,有些数据没法显示完(模拟器不能scroll?)
要自己去设置下高度,或者



3.建立索引
//返回sectionIndexTitles数组
-( NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView
{
   
return animalSectionTitles;
}
//返回对应sectionIndexTitles对应的section位置,如果不override,就默认sectionIndexTitiles数组顺序对应section数组
- (NSInteger)tableView:(UITableView*)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index
{
   
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:0inSection:index];
    [tableView
scrollToRowAtIndexPath:indexPathatScrollPosition:UITableViewScrollPositionBottomanimated:YES];
   
return index;
}
4. 微博例子 & 联系人例子

5.
不能显示索引的原因:
不能显示完全的原因
add constraints

6. section footer 不会用

7.层次化理解tableView初始化的方法
———table层面——— 
//Tableheader
//Table: number of sections      (TableViewDataSource里面的方法)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//Tablefooter
———section层面——— 
//Section: header   页眉是什么    (这种tableView前缀的都是UITableView里面的方法)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
//Section: number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//Section: footer页脚是什么
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
———row层面——— 
//row: content
- (
UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath
{
    //初始化cell过程
    staticNSString *CellIdentifier = @"Cell";
   
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   
   
if (cell == nil) {
        cell = [[
UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier];
    }
     // Configure the cell...
   
NSString *sectionTitle = [ animalSectionTitles objectAtIndex :indexPath. section ];
   
NSString *animal = [[ animals objectForKey :sectionTitle] objectAtIndex :indexPath. row ];
   
    cell.
textLabel . text = animal;
    cell.imageView.image = [UIImage imageNamed:[self getImageFilename:animal]];
  
    return cell;
}
———SectionIndex层面——— 
//sectionIndexTitles显示初始化
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
//点击sectionIndexTitles触发
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值