UITableView初级使用与理解
来源:互联网 发布:开源自动收录网站源码 编辑:程序博客网 时间:2024/06/08 04:36
UITableView在我们项目中使用的频率大家都知道是多么的频繁,所有小蒲在这里慢慢的手打下,我的博客基本都是手打的除了非常长的协议这些我command + c或v,其他基本都是手打的,一方面增加记忆,另一方面练练打字的速度,其他就不多说了,下面我们代码搞起
1:UITableView的初始化
UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0,0,CGRectGetWidth(self.view.bound),CGRectGetHeight(self.view.bounds))];
tableview.dataSouce = self;
tableview.delegete = self;
[self.view addSubView:tableview];
以上就是简单的初始化方法,基本我项目的懒加载里面就是这几句,我们看到我们遵守了协议,tableview协议里面有二个我们必须实现的方法。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return:返回uitableview的行数
}
//此方法用于跟cell赋值和cell的重用
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell;
}
这里讲下还有几个经常用的方法
//定义分组的组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return strArr.count;
}
//每组cell返回的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 0;
}
//每组尾部返回的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 20;
}
//每组头部返回的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 0) {
return 300;
}else if (section == 2){
return 300;
}
return 0;
}
//是否可以对tableview进行编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
//是否可以对tableview进行移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
//头部的进行自定义view
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerOne = [[UIView alloc]init];
if (section == 0) {
headerOne.backgroundColor = [UIColor blueColor];
}else if (section == 2){
headerOne.backgroundColor = [UIColor redColor];
}
return headerOne;
}
//尾部进行自定义view
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
//选中该cell进行下一步的操作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
以上的的方法是经常使用的,方法的使用我随便写了一点。
tableview,uicollectionview这两个都是经常用在布局上面的,下来大家可以多多的练习下
这段时间我们在做一个商场的app,增,删,tableview和collectionview很常用用到,明天我在详细的介绍下自定的tableview和数据的删除,移动,增加,今天仓促的写了一点,希望像以前我刚出来的那些初学者可以有一点帮助。
- UITableView初级使用与理解
- UI初级连载九----------UITableView的使用
- IOS初级:UITableView
- UITableView(初级应用)
- 【iOS开发】 UITableView 理解与应用
- NSTimer与UITableView同时使用
- UITableView与UIScrollView的使用
- UITableView与UITableViewCell的使用
- UITableView的使用与详解
- UITableView的创建与使用
- UITableViewController与UIViewController中使用UITableView
- UICollectionView使用以及与UITableView的区别
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
- Canvas与Paint的初级使用
- Struts2-初级配置与使用(1)
- Struts2-初级配置与使用(2)
- 【iOS开发】 UITableView 理解与应用 (增加 删除 移动)
- STM32F系列JTAG口重映射成为普通GPIO
- 左心房的守护
- EasyUI的combobox用法
- javascript中使用browser对象得到屏幕宽高,位深度以及页面的起始坐标和页面宽高
- 数到十说我想你
- UITableView初级使用与理解
- 面向51单片机的Keil uVision4基本数据类型简介
- HotSpot VM垃圾收集器拓扑图
- 颦颦停
- JZOJ4684.卡牌游戏
- bzoj 2049 SDOI 2008 Cave 洞穴勘测 [Link-Cut Tree]
- 51nod 1586 约数和
- 平安夜的思念
- 排序1