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 = [[ 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;
{
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;
{
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:0inSection:index];
[tableView scrollToRowAtIndexPath:indexPathatScrollPosition:UITableViewScrollPositionBottomanimated:YES];
return index;
}
4. 微博例子 & 联系人例子
5.
不能显示索引的原因:
不能显示完全的原因
add constraints
6. section footer 不会用
7.层次化理解tableView初始化的方法
———table层面———
//Table:header
//Table: number of sections (TableViewDataSource里面的方法)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//Table:footer
———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
- ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath
{
//初始化cell过程
staticNSString *CellIdentifier = @"Cell";
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier];
}
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;
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