UITableView(基本)--补全分割线 _tableView.separatorInset =UIEdgeInsetsZero
来源:互联网 发布:淘宝手机优惠券 编辑:程序博客网 时间:2024/05/18 20:53
#import "ViewController.h"
@interfaceViewController ()<UITableViewDelegate,UITableViewDataSource>{
UITableView* _tableView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
_tableView = [[UITableViewalloc]initWithFrame:self.view.boundsstyle:UITableViewStylePlain];
_tableView.delegate =self;
//数据源
_tableView.dataSource =self;
[self.viewaddSubview:_tableView];
[_tableView release];
//背景视图
UIImageView* imageView = [[UIImageViewalloc]initWithFrame:self.view.bounds];
imageView.image = [UIImageimageNamed:@"10_0.jpg"];
//_tableView.backgroundView = imageView;
[imageViewrelease];
//行高
_tableView.rowHeight =100;
//分割线类型
//_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//分割线颜色
_tableView.separatorColor = [UIColorblueColor];
//分割线Inset
_tableView.separatorInset =UIEdgeInsetsZero;
//重新加载数据
//[_tableView reloadData];
}
//添加索引
- (NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{
return@[@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j"];
}
//组和索引对应关系
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
NSLog(@"%@---%ld", title, index);
return index;
}
//多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return10;
}
//组头标题
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [NSStringstringWithFormat:@"组%ld", section];
}
//组头视图
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(0,0, tableView.frame.size.width,50)];
label.text = [NSStringstringWithFormat:@"组视图%ld", section];
return [labelautorelease];
}
//组头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return50;
}
//组尾标题
- (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
return [NSStringstringWithFormat:@"end%ld",section];
}
//组尾视图
//- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//
//}
//组尾高度
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//
//}
//必须实现的方法
//多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section ==0) {
return5;
}elseif (section ==1){
return10;
}
return20;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//队列描述符
staticNSString* ID =@"ID";
//从ID队列里面去获取Cell
UITableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:ID];
//如果为空,队列里面是没有的,创建一个cell
if (cell ==nil) {
//1.类型 2.队列
//当出了屏幕以后,cell会自动保存到名字叫做ID的队列中
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID]autorelease];
//选中样式
//cell.selectionStyle = UITableViewCellSelectionStyleNone;
//选中背景视图
UIImageView* imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, tableView.frame.size.width, tableView.rowHeight)];
imageView.image = [UIImageimageNamed:@"Nav_Bg.png"];
cell.selectedBackgroundView = imageView;
[imageViewrelease];
//扩展类型
cell.accessoryType =UITableViewCellAccessoryDetailButton;
//扩展视图
UISwitch* mySwitch = [[UISwitchalloc]init];
cell.accessoryView = mySwitch;
// UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
// label.tag = 10;
// [cell addSubview:label];
// [label release];
}
// UILabel* label = (UILabel*)[cell viewWithTag:10];
// label.text = [NSString stringWithFormat:@"%ld",indexPath.row];
cell.textLabel.text = [NSStringstringWithFormat:@"%ld",indexPath.row];
cell.detailTextLabel.text =@"副标题/详情...";
cell.imageView.image = [UIImageimageNamed:@"gerenzhuye.png"];
return cell;
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
NSLog(@"点击了第%ld行Button", indexPath.row);
}
//选中一行调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"选中%ld组的%ld行", indexPath.section, indexPath.row);
}
//隐藏状态栏
- (BOOL)prefersStatusBarHidden{
returnYES;
}
@end
- UITableView(基本)--补全分割线 _tableView.separatorInset =UIEdgeInsetsZero
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始 (这个和我之前的有点区别)
- iOS7 tableview separatorInset cell分割线左对齐
- iOS7 tableview separatorInset cell分割线左对
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- iOS8 设置TableView Separatorinset 分割线从边框顶端开始
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- iOS8 设置TableView Separatorinset 分割线从边框顶端开始
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- iOS 8下设置cell的分割线缩进separatorInset
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- iOS7 tableview separatorInset cell分割线左对齐
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- iOS7 tableview separatorInset cell分割线左对齐
- iOS 8下设置cell的分割线缩进separatorInset
- TableView Separatorinset 分割线从边框顶端开始
- Invalidate(TRUE)与Invalidate(FALSE)区别
- iOS6 内存警告
- NYOJ40一笔画问题
- 获得资源数组
- Windows下用户如何获取管理员权限
- UITableView(基本)--补全分割线 _tableView.separatorInset =UIEdgeInsetsZero
- 第六章 线程
- Elasticsearch基础教程
- 练手小项目__vivi移植
- 程序语言基础知识
- HDU 2841-Visible Trees(容斥原理)
- android在线源代码opengrok
- UVa 705 - Slash Maze
- hdu 4771 Stealing Harry Potter's Precious 状压bfs