iOS-Plist

作者: Wang99 | 来源:发表于2018-01-15 09:10 被阅读0次
#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

相关文章

网友评论

      本文标题:iOS-Plist

      本文链接:https://www.haomeiwen.com/subject/nulroxtx.html