iOS-Plist
2018-01-15 本文已影响0人
Wang99
#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