如果是在ViewContorller上使用 UITableView 则需要在.h文件实现表示图的
两个代理<UITableViewDelegate,UITableViewDataSource>
其中,dataSource是管理表示图显示多少行,跟每一行的内容的代理。
tableView:cellForRowAtIndexPath方法
tableView:numberOfRowsInSection方法
而delegate则是管理表示图的行高,行距,节点,表头,表底等等一些设置的。
UITbalView的各种方法总结:
//section节数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//每个section的标题 名字
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [abcArray objectAtIndex:section];
}
//右侧 索引
- (NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{
return abcArray;
}
//返回Section标题内容
-(NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section{
}
//section里面每一行的内容
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIndentifier = @"DatasCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIndentifier];
//:UITableViewCell有4种style,default只显示image和文本标签;subtitle显示image,文本标签和详细文本(位于文本标签下方);value1显示image,文本标签和详细文本(位于文本标签右边);value2只显示文本标签和详细文本(文本标签小字体,详细文本粗体)
//分割线的样式:UITableViewCellSeparatorStyleNone 无分割线,UITableViewCellSeparatorStyleSingleLine 单分割线,UITableViewCellSeparatorStyleSingleLineEtched 被侵蚀的单分割线
}
cell.textLabel.text = [carsNameArrayobjectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[NSStringstringWithFormat:@"Audi.png"]];
return cell;
}
//一共有多少行
-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
return [carsNameArray count];
}
//每一行的 行高 (self.tableView.rowHeight = 80;)或者重写下面的方法
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60;
}
//行缩进
-(NSInteger)tableView:(UITableView *)tableViewindentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row =[indexPath row];
return row;
}
//行点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
NSLog(@"chick %ld line",(long)indexPath.row);
}
//判断选中的行
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSUIntegerrow =[indexPathrow];
if(row ==0)
return nil;
returnindexPath;
}
//划动cell是否出现del按钮
-(BOOL)tableView:(UITableView *)tableViewcanEditRowAtIndexPath:(NSIndexPath *)indexPath{
}
//自定义划动时del按钮内容
-(NSString *)tableView:(UITableView *)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
}
//编辑状态
-(void)tableView:(UITableView *)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
}
未完。