UITableView

    //创建表格视图

    //参数1: 位置

    //参数2: 风格, 有两种(Plain,Grouped)

    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

 

    //设置代理, 两个代理, 一个数据源(提供数据), 另外一个delegate控制显示和处理事件

    //协议: UITableViewDataSource,UITableViewDelegate

 

    //  dataSource必须实现两个必选方法

_tableView.delegate = self;

    _tableView.dataSource = self;

    [self.view addSubview:_tableView];

    //注册cell

    [_tableView registerClass:[UITableViewCell classforCellReuseIdentifier:@"cell];//可替代下面注释

 

 

//分割线

    _tableView.separatorColor = [UIColor redColor];

    //_tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

 

    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

}

 

 1 #pragma mark - 代理方法
 2 
 3 //返回段数/组数
 4 //注意: 如果不实现,默认返回1
 5 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 6 {
 7     return _dataArray.count;
 8 }
 9 
10 //代理方法, 由tableView调用, 想让界面返回数据行数
11 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
12 {
13     NSLog(@"%lu",section);
14     NSLog(@"-----");
15     return _dataArray.count;
16 }
17 
18 //代理方法, 由tableView, 显示某行数据执行, 想让界面返回单元格, 数据存储在单元格中
19 //  简单版本(有问题的版本)
20 //参数1: 传入tableView
21 //参数2: 某行的位置, 两个属性section, row
22 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
23 {

 

posted @ 2015-08-26 14:12  Caolongs  阅读(49)  评论(0)    收藏  举报