ios plist 解析数据

1. 新建plist 文件

ios plist 解析数据_第1张图片

2.MVC model.h 定义属性 调用

3.新建 .m  @property(nonatomic,strong) NSMutableArray * dataarr; //定义数组属性

_dataarr = [NSMutableArray new];

    NSString *file = [[NSBundle mainBundle]pathForResource:@"music.plist" ofType:nil];

    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:file];

    for(NSDictionary*dic1indic[@"Cell"]) {

        SongModel* model = [SongModelnew];

        [modelsetValuesForKeysWithDictionary:dic1];

        [self.dataarraddObject:model];

    }

    [self.table reloadData];

赋值到cell里

cell.imageView.image =[UIImage imageNamed:[self.dataarr[indexPath.row]image]];

    cell.textLabel.text= [self.dataarr[indexPath.row]textT1];

    cell.detailTextLabel.text= [self.dataarr[indexPath.row]textT2];

    cell.textLabel.numberOfLines = 0;

    cell.accessoryType = 1;


高度

-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

    return 70;

}

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{

    return 200;

}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section{

  viewHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

    //viewHeader.backgroundColor = [UIColor orangeColor];

 return viewHeader;

}

你可能感兴趣的:(ios plist 解析数据)