Oc & Swift

Day.03.03 UITableView 基础

2016-03-03  本文已影响14人  挂树上的骷髅怪
#import "ViewController.h"
                            //协议
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /*______ UITableView 表视图 _____________________________________________*/
    
    //1.创建: frame style
    
    /**
     UITableViewStylePlain,   表示单元格不分组
     UITableViewStyleGrouped  表示单元格分组
     */
                                                    //不知道怎么分组
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    
    //2.属性
    tableView.dataSource = self;
    tableView.delegate = self;
    
    //3.方法
    
    //4.显示
    [self.view addSubview:tableView];
    
}

#pragma mark - UITableViewDataSource 数据源协议方法

//返回 每一组有多少个单元格
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 50;
}

//返回 每一个单元格的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //1.创建 单元格
    
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    //2.设置单元格的相关内容 --> 参考   NSIndexPath section:组下标 row:行下标
    
    cell.textLabel.text = [NSString stringWithFormat:@"section:%ld - row:%ld ",indexPath.section,indexPath.row];
    
    //3.返回单元格
    return cell;
}

@end



plain //平原  代表不分组
grouped //分组
dataSource //数据源
delegate //代表 代理
count //计数
屏幕快照 2016-03-03 上午9.10.50.png
上一篇 下一篇

猜你喜欢

热点阅读