资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

iOStableView的用法

- (void)viewDidLoad

创新互联建站专注于铁山网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供铁山营销型网站建设,铁山网站制作、铁山网页设计、铁山网站官网定制、微信小程序开发服务,打造铁山网络公司原创品牌,更为您提供铁山网站排名全网营销落地服务。

{

    [super viewDidLoad];


    UITableView *myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Screen_width, Screen_height)style:UITableViewStylePlain];

//    UITableViewStyleGrouped分组

    myTableView.dataSource = self;

    myTableView.delegate = self;

    [self cancelCell:myTableView];

    [self.view addSubview:myTableView];

       // Do any additional setup after loading the view,;typically from a nib.

}


#pragma mark-once 行数

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

{

    return 3;

}


#pragma mark-once 行内容

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

{

   static NSString *cellID = @"cellID";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:cellID];

    if(cell==nil)

    {

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

    }

    //UITableViewCellStyle          是个枚举

    //UITableViewCellStyleDefault;  默认的

    //UITableViewCellStyleSubtitle;

    //UITableViewCellStyleValue1;

    //UITableViewCellStyleValue2;

    cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];

    

    //给右边加个标识符的

    cell.accessoryType  =UITableViewCellAccessoryDisclosureIndicator;

    //选中的颜色

    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    

    return cell;

}


#pragma mark-once 几组

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

{

    return 2;

}


#pragma mark-once头标题

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

{

  return @"第一个标题";

}


#pragma mark-once未标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    return @"最后一个标题";

 

}


#pragma mark-once标识符accessoryButtonTappedForRow方法

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{


}


#pragma mark-once类似电话那种最右边的 a,b,c,d,e-z

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

{

    NSArray *rightArry = @[@"A",@"B",@"c",@"d",@"e",@"f",@"g"];

    return rightArry;

}

#pragma mark-once行高

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

{

    return 50;

}


#pragma mark-once头标题的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 50;

}


#pragma mark-once未标题的高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 50;

}


#pragma mark-once行高

-(void)cancelCell:(UITableView *)tableView

{

    UIView *view = [UIView new];

    view.backgroundColor = [UIColor clearColor];

    [tableView setTableFooterView:view];

    view.frame = CGRectMake(0, 0, tableView.frame.size.width, 20);

}


#pragma mark-once 选中的方法

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

{

    NSLog(@"%ld",(NSInteger)indexPath.row);

}


#pragma mark-once编辑的方法

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

{

    return YES;

}


#pragma mark-once是否允许移动

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    return YES;

}


#pragma mark-once 编辑的方法

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

{

}


#pragma mark-once 移动的方法

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath

{


}

#pragma mark-once 分割线

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    

    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {

        [tableView setSeparatorInset:UIEdgeInsetsZero];

    }

    

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {

        [tableView setLayoutMargins:UIEdgeInsetsZero];

    }

    

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

        [cell setLayoutMargins:UIEdgeInsetsZero];

    }

}


文章标题:iOStableView的用法
分享网址:http://cdkjz.cn/article/ghiieo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220