UITableView Group

浏览量:5249 | 分类:objective-c | 发布日期:2015-02-16

最近有空捣腾下OC
下面是UITableView一个最简单的栗子~

 

DetailViewController.h

//
//  DetailViewController.h
//  tablefzxa
//
//  Created by fzxa wang on 15-2-8.
//  Copyright (c) 2015年 Fzxa wang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController

 

DetailViewController.m

//
//  DetailViewController.m
//  tablefzxa
//
//  Created by fzxa wang on 15-2-8.
//  Copyright (c) 2015年 Fzxa wang. All rights reserved.
//

#import "DetailViewController.h"

@implementation DetailViewController

-(void)loadView
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, kDeviceHeight)];
    self.view = view;
    self.title = @"Group";
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, kDeviceHeight) style:(UITableViewStyleGrouped)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
    
    NSArray *array = [UIFont familyNames];
    NSMutableArray *temp = nil;
    _fontArray = [[NSMutableArray alloc]initWithCapacity:71];
    //NSLog(@"fontcount: %d", [array count]);
    
    for ( int index = 0; index < [array count]; index++)
    {
        NSString *font = array[index];
        if(index % 5 == 0)
        {
            temp = [[NSMutableArray alloc]initWithCapacity:5];
            [_fontArray addObject:temp];
        }
        [temp addObject:font];
    }
    //NSLog(@"list :%@",_fontArray);
    
    [self.view addSubview:_tableView];
    
}

//table中有多少section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_fontArray count];
}

//section中有多少row
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_fontArray[section]count];
}

//section header title
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
    NSString *title = [NSString stringWithFormat:@"Header Section NO %d",section+1];
    return title;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    
    NSString *title = [NSString stringWithFormat:@"Footer Section NO %d",section+1];
    return title;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tid = @"detailCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tid];
    
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tid];
    }
    cell.textLabel.text = [[_fontArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    
    return cell;
}

@end

上一篇: Python做代码生成器

下一篇: Python微信红包算法

评论

过客   2016-04-05 04:34:06