首页 > 移动平台 > 详细

ios初识UITableView及简单用法

时间:2017-08-25 15:27:42      阅读:266      评论:0      收藏:0      [点我收藏+]

技术分享

//
//  ViewController.m
//  ZQRTableViewTest
//
//  Created by zzqqrr on 17/8/24.
//  Copyright (c) 2017年 zzqqrr. All rights reserved.
//

#import "ViewController.h"

@interface ViewController () <UITableViewDataSource>
@property (weak,nonatomic) IBOutlet UITableView *tableView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource=self;
}
/** 设置组 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 if(section==0)//第一组
 {
     return 1;
 }
 else if(section==1)//第二组
 {
     return 2;
 }
 else
 {//第三组
     return 3;
 }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    if(indexPath.section==0){
        cell.textLabel.text=@"第一组第一行";
    }else if(indexPath.section==1)
    {
        if(indexPath.row==0){
         cell.textLabel.text=@"第二组第一行";
        }else if(indexPath.row==1){
             cell.textLabel.text=@"第二组第二行";
        }
    }
    else{
        if(indexPath.row==0){
            cell.textLabel.text=@"第三组第一行";
        }else if(indexPath.row==1){
            cell.textLabel.text=@"第三组第二行";
        }else{
            cell.textLabel.text=@"第三组第三行";
        }
        }
    
    return cell;
}
@end

 

ios初识UITableView及简单用法

原文:http://www.cnblogs.com/zqrios/p/7428187.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!