首页 > 移动平台 > 详细

iOS开发学习之#表视图#(4)填充Grouped风格的分组表

时间:2014-12-01 17:36:12      阅读:349      评论:0      收藏:0      [点我收藏+]

直接上代买吧:

@implementation ViewController

- (void)viewDidLoad {
    a = [NSArray arrayWithObjects:@"ant",@"alpaca",@"albatross", nil];
    b = [NSArray arrayWithObjects:@"badger",@"bat",@"bear", nil];
    c = [NSArray arrayWithObjects:@"cat",@"calf",@"cattle", nil];
    d = [NSArray arrayWithObjects:@"A",@"B",@"C", nil];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
//设置表视图的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = [a objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 1) {
        cell.textLabel.text = [b objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 2) {
        cell.textLabel.text = [c objectAtIndex:indexPath.row];
    }
    return cell;
}
//设置表视图的节数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [d count];
}
//获取节的名称
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [d objectAtIndex:section];
}


iOS开发学习之#表视图#(4)填充Grouped风格的分组表

原文:http://blog.csdn.net/u010710758/article/details/41649829

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!