笔记目录:
1 表视图一
1.1 表视图的基本概念
1.2 创建基本表格实例1
1.3 表视图的常用属性和方法
1.4 设置表视图属性实例2
1.5 表视图委托方法和数据源方法
1.6 委托方法实例3-1
1.7 委托方法实例3-2
1.8 单元格的基本概念
1.9 单元格风格和修改单元格背景实例4
1.10 单选TableView实例5
1.11 计算表视图单元格的高度实例6
1.12 索引表视图实例7
2 表视图二
2.1 表视图控制器的基本概念
2.2 单元格的常用属性
2.3 定制单元格的方式概念
2.4 第一种定制cell的方式1
2.5 第二种定制cell的方式2
2.6 第三种定制cell的方式3
2.7 编辑表视图的基本概念
2.8 课堂实例2
2.9 多选模式
2.10 课堂实例3
学习视频
无线互联iOS开发视频
详细笔记:
1 表视图一
1.1 表视图的基本概念
1) 重点掌握:常用属性和方法、数据源方法和委托方法、委托方法调用顺序、单元格的基本类型和重用
2) 表视图的两种风格:UITabelViewStylePlain、UITabelViewStyleGrouped
3) 表视图的结构
a) 表视图是由头部、尾部视图、中间一连串单元格视图组成
b) 表视图的头部是由tableHeaderView属性设置,尾部视图通过tableFooterView属性设置
c) 分组表格由一连串的section视图组成,每一个section又包含一个连续的单元格组
d) 每一个section视图也有头部(与表视图的头部不同)和尾部视图,通过委托方法设置
4) 创建一个简单地表视图
_tableView = [[UITabelView alloc]initWithFrame:CGRectMake(0,0,320,460-44) style:UITabelViewStylePlain; _tabelView.delegate = self; // 设置tableView的委托 _tabelView.dataSource = self; // 设置tabelView的数据委托 [self.view addSubview:_tableView];
// 以下两个数据源方法必须强制实现 – (NSInteger)tableView:(UITabelView *)tableViewnumberOfRowsInSection:(NSInteger)section{ return 20; } // 返回section拥有的单元格的数目,一般用数组的形式表示section中有几行[array count]
– (UITabViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ satic NSString *identifier = @”myCell”; // 检查、查询是否有闲置的单元格 UITabelViewCell *cell = [ tableViewdequeueReusableCellWithIdentifier:identifier]; if ( cell == nil ){ cell= [[ UITabelViewCell alloc ] initWithStyle:UITabelViewCellStyleDefaultreuseIdentifier:identifier ] autorelease ]; } return cell; } // 返回单元格对象
1.2 创建基本表格实例1
FontTableViewDemo
1.3 表视图的常用属性和方法
1) 常用属性
a)设置表视图分割线风格 @property (nonatomic) UITableViewCellSeparatorStyleseparatorStyle; b)设置表视图分割线颜色,默认标准灰色 @property (nonatomic,retain) UIColor*separatorColor; c)设置表视图的头部视图 @property (nonatomic,retain) UIView*tableHeaderView; d)设置表视图的尾部视图 @property (nonatomic,retain) UIView*tableFooterView; e)设置表视图单元格的行高 @property (nonatomic) CGFloatrowHeight; f)设置表视图section的头部行高 @property (nonatomic) CGFloatsectionHeaderHeight; g)设置表视图section的尾部行高 @property (nonatomic) CGFloatsectionFooterHeight; h)设置表视图的背景 @property (nonatomic,readwrite,retain)UIView *backgroundView; i)默认为NO,不可以编辑,设置时,不存在动画效果 @property (nonatomic,getter=isEditing)BOOL editing; j)覆盖此方法,存在动画效果 - (void)setEditing:(BOOL)editinganimated:(BOOL)animated; k)默认为YES,当表视图不存在编辑时,单元格时候可以选中 @property (nonatomic) BOOL allSelectionNS——AVALIABLE_IOS(3_0); l)默认为NO,当表视图在编辑时,单元格是否可以选中 @property (nonatomic) BOOLallowSelectionDuringEditing; m)默认为NO,是否可以同时选中多个单元格,注意版本问题 @proerty (nonatomic) BOOLallowMultipleSelection; NS_AVALIABLE_IOS(5_0) n)默认为NO,在编辑状态下,是否可以同时选中多个单元格,注意版本问题 @property (nonatomic) BOOLallowsMultipleSelectionDuringEditing; NS_AVALIABLE_IOS(5_0)
2) 常用方法(普通方法)
a)刷新表视图单元格中的数据 - (void)reloadData; b)刷新表视图section中的数据 - (void)reloadSectionIndexTitles; c)滑到指定行的位置,可以配置动画 -(void)scrollToRowAtIndexPath:(NSIndexPath *)indexPathatScrollPosition:scrollPosition animated:(BOOL)animited; d)制定一个cell,返回NSIndexPath实例,如果cell没有显示,返回nil - (NSIndexPath*)indexPathForCell:(UITableViewCell *)cell; e)指定一个范围,返回一个数组,内容是NSIndexPath实例,指定rect无效,返回nil - (NSArray *)indexPathssForRowsInRect:(CGRect*)rect; f)指定一个NSIndexPath,返回一个cell实例,如果cell没有显示,返返回为nil - (UITabelViewCell*)cellForRowAtIndexPath:(NSIndexPath *)indexPath; g)根据显示的cell,返回一组cell实例的数组,如果没有显示,返回nil - (NSArray *)visibleCells; h)根据显示的cell&#