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的用法
转载来于:https://www.cdcxhl.com/article40/ghiieo.html

成都网站建设公司_创新互联,为您提供服务器托管面包屑导航网站排名网站改版Google品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设