tableView的常见属性

1.tableView展示数据的过程

调用数据源的下面方法得知一共有多少组数据
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;


调用数据源的下面方法得知每一组有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;


调用数据源的下面方法得知每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

2.实例


//
//  MJViewController.m


#import "MJViewController.h"

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

@end

@implementation MJViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    // 32bit颜色 : ARGB
    // Alpha : 8
    // Red : 8
    // Green : 8
    // Blue : 8
    
    // 24bit颜色 : RGB
    // Red : 8
    // Green : 8
    // Blue : 8
    
    // #ff ff ff  白色
    // #00 00 00  黑色
    // #ff 00 00  红色
    // # ff ff 00
    // #ff ff ff ff
    
    // 每一个颜色通道占据8个二进制位
    // 每一个颜色通道的取值范围是[0, 255]
    
    // R 78
    // G 100
    // B 255
    
    // # ff ff 00 ff
    
    self.tableView.separatorColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:0 alpha:255/255.0];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    // 表格的头部控件(直接显示表格的最顶部)
    self.tableView.tableHeaderView = [UIButton buttonWithType:UIButtonTypeContactAdd];
    self.tableView.tableFooterView = [[UISwitch alloc] init];
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    cell.textLabel.text = [NSString stringWithFormat:@"第%d行数据", indexPath.row];
    
    return cell;
}

@end


3.运行结果

tableHeaderView属性

tableFooterView属性

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值