iOS-Plist

#import "ViewController.h"
#import "friend.h"
#import "friendViewController.h"
#import "model.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

{
    friend *fri;
    model *models;
    UITableView *_table;
    NSMutableArray *arraymodel;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   //
    NSString *path = [[NSBundle mainBundle]pathForResource:@"friends.plist" ofType:nil];
    NSArray *array = [[NSArray alloc]initWithContentsOfFile:path];
   arraymodel = [NSMutableArray array];
    
    for (NSDictionary *dics in array) {
        //初始化模型
        models = [[model alloc]init];
        models.friends = dics[@"friends"];
        models.name = dics[@"name"];
        models.online = dics[@"online"];
        
        //将模型的对象添加到数组
        [arraymodel addObject:models];
        
    }
    
    //初始化表格
    _table = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _table.delegate = self;
    _table.dataSource = self;

    [self.view addSubview:_table];
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return arraymodel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"cellID";
    UITableViewCell *cell
    = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }
    model *mo = [[model alloc]init];
    mo = arraymodel[indexPath.row];
    cell.textLabel.text = mo.name;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",mo.online];

    return cell;
}
@end
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容