UITableView详解

一、建立 UITableView


DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];

 [DataTable setDelegate:self];

 [DataTable setDataSource:self];

 [self.view addSubview:DataTable];

二、UITableView各Method说明

//Section总数


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{

 return TitleData;

}

// Section Titles

//每个section显示的标题


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

 return @"";

}

//指定有多少个分区(Section),默认为1


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

 return 4;

}

//指定每个分区中有多少行,默认为1


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

}

//绘制Cell


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

  

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:

                             SimpleTableIdentifier];

    if (cell == nil) {  

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault

                                       reuseIdentifier: SimpleTableIdentifier] autorelease];

 }

 cell.imageView.image=image;//未选cell时的图片

 cell.imageView.highlightedImage=highlightImage;//选中cell后的图片

 cell.text=//.....

 return cell;

}

//行缩进


-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{

 NSUInteger row = [indexPath row];

 return row;

}

//改变行的高度


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 40;

}

//定位


[TopicsTable setContentOffset:CGPointMake(0, promiseNum * 44 + Chapter * 20)];

//返回当前所选cell


NSIndexPath *ip = [NSIndexPath indexPathForRow:row inSection:section];

[TopicsTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];

 

[tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];

//选中Cell响应事件


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

 [tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失

}

//判断选中的行(阻止选中第一行)


-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSUInteger row = [indexPath row];

    if (row == 0)

        return nil;

   

    return indexPath;

}

//划动cell是否出现del按钮


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

}

//编辑状态


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle

forRowAtIndexPath:(NSIndexPath *)indexPath

{

}

[topicsTable setContentSize:CGSizeMake(0,controller.promiseNum * 44)];

//右侧添加一个索引表


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{

}

//返回Section标题内容


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

}

//自定义划动时del按钮内容


- (NSString *)tableView:(UITableView *)tableView

titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

//跳到指的row or section


[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];

三、在UITableViewCell上建立UILable多行显示


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";   

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

  UILabel *Datalabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)];

  [Datalabel setTag:100];

  Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

  [cell.contentView addSubview:Datalabel];

  [Datalabel release];

 } 

 UILabel *Datalabel = (UILabel *)[cell.contentView viewWithTag:100];

 [Datalabel setFont:[UIFont boldSystemFontOfSize:18]];

 Datalabel.text = [data.DataArray objectAtIndex:indexPath.row];

 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}

//选中cell时的颜色


typedef enum {

    UITableViewCellSelectionStyleNone,

    UITableViewCellSelectionStyleBlue,

    UITableViewCellSelectionStyleGray

} UITableViewCellSelectionStyle

//cell右边按钮格式


typedef enum {

    UITableViewCellAccessoryNone,                   // don't show any accessory view

    UITableViewCellAccessoryDisclosureIndicator,    // regular chevron. doesn't track

    UITableViewCellAccessoryDetailDisclosureButton, // blue button w/ chevron. tracks

    UITableViewCellAccessoryCheckmark               // checkmark. doesn't track

} UITableViewCellAccessoryType

//是否加换行线


typedef enum {

    UITableViewCellSeparatorStyleNone,

    UITableViewCellSeparatorStyleSingleLine

} UITableViewCellSeparatorStyle//改变换行线颜色

tableView.separatorColor = [UIColor blueColor];

三、设置cell边框线长度


 tableView.separatorInset=UIEdgeInsetsZero;

四、设置cell边框线颜色


tableView.separatorColor = Colour(224, 231, 227, 1);

   五、设置没有内容的cell没有分割线

    原理:从新对footView进行重置


    table.tableFooterView = [[UIView alloc] init];

六、设置UITableView是否显示滚动条


[table setShowsHorizontalScrollIndeiator:YES];  //设置水平滚动条可见

[table setShowsVerticalScrollIndicator:YES];      //设置垂直滚动条可见

七、当点击cell时显示灰色,取消点击后显示正常颜色


[tableView deselectRowAtIndexPath:indexPath animated:YES];

八、删除某一行

//设置删除时编辑状态


-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle==UITableViewCellEditingStyleDelete) {  //如果是删除就从数组中移除元素

        [list removeObjectAtIndex:indexPath.row];

        [contentTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    }

}

修改名字


//-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

//{

//    return @"下载";

 

//}

九、添加一行


1、———-----

 [hist getHistoryModel:^(HistoryCaseModel *model) {

        [self.historyCaseArray addObject:model];

       [contentTableView beginUpdates];

       [contentTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:self.historyCaseArray.count-1 inSection:2]] withRowAnimation:UITableViewRowAnimationFade];

       [contentTableView endUpdates];

//

   }];


 

2、----------

- (void)viewDidLoad

{

    [super viewDidLoad];

    contentTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];

    [contentTableView setEditing:YES animated:YES];

    contentTableView.delegate = self;

    contentTableView.dataSource =self;

    

    [self.view addSubview:contentTableView];

    

    

    array = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4", nil];

}

#pragma mark - UITableViewDelegate**UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return array.count;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell==nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    }

    cell.textLabel.text = array[indexPath.row];

    

    return cell;

}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSUInteger row = [indexPath row];

    if(editingStyle==UITableViewCellEditingStyleInsert)

    {

        NSArray *insertIndexPaths = [NSArray arrayWithObjects:indexPath, nil];

        [array insertObject:@"insert new cell" atIndex:row];

        [tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationMiddle];

    }

}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return UITableViewCellEditingStyleInsert;

}

//设置分割线长度


[self.contentTableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];

//加载xib文件cell


  cell=[[[NSBundle mainBundle]loadNibNamed:@"ActivitieTableViewCell" owner:self options:nil]lastObject];




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值