Day.02.29 UI表视图数据


#import "ViewController.h"

@interface ViewController ()
{
    NSArray *_dataList;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
    tableView.dataSource = self;
    
    tableView.delegate = self;
    
    [self.view addSubview:tableView];
    
//    _dataList = [UIFont familyNames];
    
    /*
        从工程目录中读取文件
     */
    
    NSString *path = [[NSBundle mainBundle]pathForResource:@"font" ofType:@"plist"];
    
    _dataList = [NSArray arrayWithContentsOfFile:path];
    
    NSLog(@"%@",_dataList);
}

#pragma mark -- UITableViewDataSource

//可选方法:返回 组个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return  _dataList.count;//组个数
    
}

//返回 每个组有多少个单元格
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        
        //1.从datalist 中获取section 下标对一个的对象 -- > 小数组(盛放的NSString)
        NSArray *suArray = _dataList[section];
    
        return suArray.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        
        
        //1.
        static NSString *identifier = @"font_cell";
        
        //2.
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        //3.
        if (cell == nil) {
            
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            
        }
        
        //1.不分组的情况下
//        cell.textLabel.text = [_dataList objectAtIndex:indexPath.row];
//        
//        cell.textLabel.font = [UIFont fontWithName:[_dataList objectAtIndex:indexPath.row]size:20];
        
        //2.分组
        
            //1.在datalist中  找到section对应的二级数组
        NSArray *subArray = _dataList[indexPath.section];
        
            //2.在二级数组中  找到row 对应的字符串对象
        cell.textLabel.text = subArray[indexPath.row];
        
        cell.textLabel.font = [UIFont fontWithName:subArray[indexPath.row] size:20];
        
        
        
    
        return cell;
    }

@end


section //组的下标
cancel  //取消
Day.02.29 UI表视图数据_第1张图片
屏幕快照 2016-02-29 下午7.29.55.png

你可能感兴趣的:(Day.02.29 UI表视图数据)