UITableView
来源:互联网 发布:玩具战争防御塔数据 编辑:程序博客网 时间:2024/06/08 02:25
UITableView,如其义,多用于以表格的形式展示数据。基本用法如下:
1、创建
self.tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0, 320,460) style:UITableViewStyleGrouped];
2、常见属性设置
self.tableView.separatorStyle =UITableViewCellSeparatorStyleSingleLine;
self.tableView.separatorColor = [UIColorredColor];
self.tableView.backgroundColor = [UIColororangeColor];
3、设置delegate及datasource
self.tableView.delegate =self;
self.tableView.dataSource =self;
4、实现dataSource和delegate的方法
//必须实现的3个dataSource方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"txTableCell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = [self.dataArrayobjectAtIndex:indexPath.row];
return cell;
}
//设置tableView的tableViewCell的高度
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40.0f;
}
//设置每个section的header的高度
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50.0f;
}
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 50.0f;
}
- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertView *alertViewSelect = [[UIAlertViewalloc]initWithTitle:[NSStringstringWithFormat:@"您已选中了%d行",indexPath.row] message:@"您已选中了" delegate:nil cancelButtonTitle:@"取消选中" otherButtonTitles:@"确认选中",nil];
[alertViewSelect show];
}
详细代码可以参照:https://github.com/tingxuan/txUITableViewDemo
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableview
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView,
- UITableView
- UITableView
- UITableView
- UITableView
- 冒个泡
- sgu 525 Revolutionary Roads
- Android am命令
- 持续集成与测试自动化
- sgu 195 New Year Bonus Grant 树形dp
- UITableView
- 手把手教你mysql(十)索引
- Java 单例的两种方法示例
- 俞敏洪:笨有笨的好处
- memset原理(为什么只能初始化成0或者-1)
- 十四周——选择排序
- 【数组】14周项目六(三)。去除str1中的空格,仍保存在str1中(贺while版)
- 男人身上必须有的15种修养,让你乘风破浪!
- 二进制音频流文件解码成数值文件遇到的问题