ios - UITableViewController 笔记

如果是在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
{
 
未完。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值