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

来源:互联网 发布:万网已备案域名 编辑:程序博客网 时间:2024/05/15 04:26

直接上代买吧:

@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];}


0 0