表格视图

87 篇文章 0 订阅

//2、实现数据源协议

@interface SettingViewController ()<UITableViewDataSource,UITableViewDelegate>



@property(nonatomic,strong) SettingView *settingView;


@property(nonatomic,strong) NSArray *biggerArrays;


@end


@implementation SettingViewController



-(void)loadView

{

    self.settingView = [[SettingView alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.view = self.settingView;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    

    //1、设置数据源

    self.settingView.tableView.dataSource = self;

    self.settingView.tableView.delegate = self;

    

    //初始化数据

    self.biggerArrays = @[

                          @[@"通用", @"隐私"],

                          @[@"iCloud", @"地图", @"Safari",

                            @"照片与相机", @"Game Center"],

                          @[@"Twitter", @"FaceBook", @"Flickr",

                            @"Vimeo", @"新浪微博", @"腾讯微博"],

                          @[@"开发者"]

                          ];

    

}

#pragma mark 实现协议方法


#pragma mark 设置分组数,可选方法


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    //返回数字,代表几个分组

    return _biggerArrays.count;

}


#pragma mark 设置行数 ,必须实现的方法

//有多少个分区,这个方法就走多少次。===当前屏幕能显示的行数,当你的cell将要显示的时候都会执行此方法。

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

{

    //返回数字,代表行数。

    NSArray *smallArray = _biggerArrays[section];

    

    return smallArray.count;

}


#pragma mark 设置每行上显示什么内容,必须实现的方法

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

{

    

#pragma mark 重用机制

    

    //0.创建标识符

    static NSString *cellID = @"tttt";

    

    //1.从重用队列中获取cell

    UITableViewCell *cell = [tableView

                dequeueReusableCellWithIdentifier:cellID];

    

    //2.判断是否存在,如果不存在,则创建

    

    if (cell == nil) {

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

    }

    

    //3.使用

    

    cell.textLabel.text = _biggerArrays[indexPath.section][indexPath.row];

    

    

    return cell;

    

    

}



#pragma mark 设置分区标题


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

{

    return @"投标太";

}



#pragma mark 设置快速索引


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

{

    

    return @[@"1",@"2",@"3"];




}


#pragma mark 设置cell的高度

//设置不同行的不同高度

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

{

    if (indexPath.row == 0) {

        return 50;

    }

    return 44;

}


#pragma mark 选中了哪一个cell

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

{

    NSLog(@"%@",indexPath);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值