UITableView之一分组简单使用

分组也就是类似设置界面中的界面展示

这里写图片描述

1.首先在Storyboard中拖一个UITableView

这里写图片描述

2.其次设置分组属性默认是Plain我们选择Grouped

这里写图片描述

3.最后在将控件拖到代码中设置代理如下代码:
//
//  ViewController.m
//  TableView分组
//
//  Created by gaocai on 16/7/25.
//  Copyright © 2016年 gaocai. All rights reserved.
//

#import "ViewController.h"

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

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置代理
    _tableView.dataSource = self;
}

#pragma mark - UITableViewDataSource代理方法

//显示多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 4;
}

//每一组有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (section == 0) { //section组
        return 2;
    } else if (section == 1) {
        return 3;
    } else if (section == 2) {
        return 4;
    } else {
        return 5;
    }
}

//每一组的每一行都是一个UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [[UITableViewCell alloc] init];
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    if (section == 0) {
        if (row == 0) {
            cell.textLabel.text = @"通用";
        } else if(row == 1) {
            cell.textLabel.text = @"设置";
        }
    } else {

        cell.textLabel.text = @"Other";
    }
    return cell;
}

@end
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值