ios学习(UITableView1)
来源:互联网 发布:赵薇资本控制舆论知乎 编辑:程序博客网 时间:2024/06/08 16:56
1.设置每个cell之间的分割线的一些属性,设置每个分割线的颜色
_tableView.separatorColor = [UIColorredColor];
2.隐藏分割线
_tableView.separatorStyle = UITableViewRowAnimationNone;
3.设置分割的位置
if([_tableViewrespondsToSelector:@selector(setSeparatorInset:)])
{中间那个数是距离左边的距离,依次调节
_tableView.separatorInset =UIEdgeInsetsMake(0,20, 0, 50);
}
4.刷新
[_tableView reloadData];
5.系统自带的一个编辑按钮
self.navigationItem.rightBarButtonItem =self.editButtonItem;
6.响应编辑按钮
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
继承父类
[super setEditing:editing animated:animated];
[_tableView setEditing:editing animated:animated];
7.初始化等
初始化并且设置tableView的frame
_tableView = [[UITableViewalloc]initWithFrame:self.view.bounds];
8.设置代理
_tableView.delegate =self;
_tableView.dataSource =self;
}
返回分区数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
9.必须要实现的两个方法,每个section对应的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
;
10.返回section分区所对应的标题,头视图
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
11.设置对应的角标,在分区中可以看到
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
12.返回头视图,这里返回的透视图是一个vie可以在里面设置点击事件
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *vie = [[UIViewalloc]init];
vie.backgroundColor = [UIColorredColor];
return vie;
}
13.设置头视图的高度,同理也可以设置脚视图的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 50;
}
14.indexPath:包含两个值:
row:行
section:分区
这个方法的返回值,返回的是indexPath所对应的那个cell
创建出来的cell的个数,是满屏的cell的数量+1
(满屏数量=tableView的高度/cell的高度 + 1)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellid =@"cell";
当出现一个cell时,首先要从tableView的可充用队列中进行取闲置的cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
如果没有闲置的cell这时需要创建
UITableViewCellStyleSubtitle :创建一个带有副标题的cell
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:@"cell"];
15.设置标题的内容
cell.textLabel.text =_arry[indexPath.section][indexPath.row];
16.设置cell右边的按钮
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
17.点击右边按钮对应的数
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
18.返回编辑的方式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
19.响应对应的方式
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
删除,首先从数组删除,然后从tableview删除
[_arryremoveObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
添加也类似以上内容
[_arryinsertObject:@"pp"atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
20.左滑出来按钮
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
;
21.对应的ios8里面的新特性
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *action = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"pp个头"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
}];
//这里设置背景颜色
action.backgroundColor = [UIColorblueColor];
UITableViewRowAction *actionP = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"小王八"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
}];
return @[action,actionP];
}
22.设置每一个cell的高度
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath;
23.点击某一个cell时调用该方法
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
- ios学习(UITableView1)
- 黑马程序员-IOS学习笔记-UITableView1
- UI基础-iOS黑马-UITableView1-汽车品牌demo
- IOS 学习
- ios学习
- ios学习
- IOS学习
- IOS 学习
- iOS 学习
- 学习iOS
- iOS学习
- ios 学习
- IOS学习
- ios 学习
- iOS学习
- ios学习
- ios学习 - 控件学习
- IOS学习 CGContextRef学习
- 线程的同步
- Xcode的快捷键
- tombstone.c打印native crash log
- 读书笔记之c和指针(5)
- Trie树使用
- ios学习(UITableView1)
- 浅析android 四大布局
- strstr函数的对比
- 线程并发协作
- java-基础巩固 2
- 跳表(SkipList) -- 基于概率的平衡二叉树
- 听课练习(五)
- 简单的抓包演示程序
- java自定义注解的方式连接MySQL数据库来走进注解