简单tableView的使用
来源:互联网 发布:手机怎么发送淘宝链接 编辑:程序博客网 时间:2024/05/01 12:01
UITableView是一个用于显示列表的视图,可以作为子视图镶嵌在主视图上,可以滑动,选取各种参数
定义:
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
@property (nonatomic, retain) NSArray *dataList;
@property (nonatomic, retain) UITableView *myTableView;
UITableView *tableView = [[UITableViewalloc] initWithFrame:FRAME_TABLEVIEWstyle:UITableViewStylePlain];
注意:这里的两个属性 dataList和myTableView并不要求实现,只需要在头文件定义就可以了
Delegate必须要有,因为必须要实现它的接口
使用:
//init tableView
NSArray *list = [NSArray arrayWithObjects:@"模糊",@"素描",@"怀旧", nil];
self.dataList = list;
// 设置tableView的数据源
tableView.dataSource = self;
// 设置tableView的委托
tableView.delegate = self;
// 设置tableView的背景图
// tableView.backgroundView = [[UIImageView alloc] init];
self.myTableView = tableView;
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.myTableView];
常用的属性设置:
//设置转置,使table view倒过来
tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
//取消滑动出现删除
tableView.showsVerticalScrollIndicator = NO;
接口的实现:
//set cells
//定义每个列表项的属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellWithIdentifier];
}
cell.imageView.image = [UIImageimageNamed:@"example.png"];
return cell;
}
//set number of sections
//定义块的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
//行首缩进
//定义首行缩进的宽度
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 0;
}
//row height
//定义每一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 105;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// if ([indexPath row] % 2 == 0) {
// cell.backgroundColor = [UIColor blueColor];
// } else {
// cell.backgroundColor = [UIColor greenColor];
// }
}
//select rows callback
//选择某行以后的动作方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath row]) {
case 0:
testFilter = [[GPUImageFastBlurFilteralloc] init];
break;
case 1:
testFilter = [[GPUImageSketchFilteralloc] init];
break;
case 2:
testFilter = [[GPUImageSepiaFilteralloc] init];
break;
default:
break;
}
}
// delete
//选择删除以后的方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"执行删除操作");
}
//设置没有分界线
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
returnUITableViewCellEditingStyleNone;
}
//number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
returnself.dataList.count;
}
- 简单tableView的使用
- Qt TableView的简单使用
- Qt TableView的简单使用
- QT tableview的简单使用
- iOS--TableView的简单使用
- Qt TableView的简单使用
- Qt TableView的简单使用
- Qt TableView的简单使用
- UIKit-TableView--简单的TableView
- tableView 简单使用
- 简单的TableView通讯录
- 自定义简单的TableView
- 简单的tableView
- UIKit-TableView-简单的TableView细节扩展
- IOS_简单创建tableView并使用自定义的单元格
- ios开发中最简单的tableview使用一
- iOS开发系列----UI(简单TableView的使用)
- TableView的使用
- 用GPUImage开启相机并且开启滤镜效果
- 使用GPUImage开启的相机进行摄像,保存写入到Path
- sql 2000打开企业管理器时报mmc不能打开文件SQL Server Enterprise Manager.MSC解决方案
- 通过UIImagePickerController完成照相和相片的选取
- oracle 创建表空间 用户授权
- 简单tableView的使用
- 中国有没有‘乔布什’?
- 将博客搬至CSDN
- microsoft的罗马帝国——浪潮之巅
- apple公司的潮起潮落——浪潮之巅
- 模拟IC
- 火车上的奇遇
- mac下的改装人生——关于机械键盘
- mac下的改装人生——关于ssd