plist 文件



NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    //获取完整路径

    NSString*documentsPath = [pathobjectAtIndex:0];

    NSString*plistPath = [documentsPathstringByAppendingPathComponent:@"usersList.plist"];

    NSMutableArray *usersArray = [[NSMutableArray alloc ] init];



    //多层次结构

    //定义第一个类的属性

    NSMutableDictionary *dic1 = [[NSMutableDictionary alloc]init];

    [dic1setObject:@"chan" forKey:@"name"];

    [dic1setObject:@"123456" forKey:@"password"];

    //定义第二个类的属性

    NSMutableDictionary *dic2 = [[NSMutableDictionary alloc]init];

    [dic2setObject:@"db" forKey:@"name"];

    [dic2setObject:@"sbsbsb" forKey:@"password"];

    //定义第二个类的属性

    NSMutableDictionary *dic3 = [[NSMutableDictionary alloc]init];

    [dic3setObject:@"db1" forKey:@"name"];

    [dic3setObject:@"sbsbsb1" forKey:@"password"];


    //添加数组元素

    [usersArrayaddObject:dic1];

    [usersArrayaddObject:dic2];

    [usersArrayaddObject:dic3];

    //写入文件

    [usersArraywriteToFile:plistPathatomically:YES];


    NSLog(@"路径%@",plistPath);

    NSLog(@"内容%@",usersArray);



    _array= [[NSMutableArrayalloc]initWithArray:usersArray];

//    _array = [data1 objectForKey:@""];

    NSLog(@"_array文件%@",_array);

    /*

     ***tableView

     */

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-20) style:UITableViewStylePlain];

    self.tableView.dataSource = self;

    self.tableView.delegate=self;

    [self.viewaddSubview:self.tableView];

    self.tableView.tableFooterView = [[UIView alloc]init];//去掉多余的空白cell

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView

{

    // Return the number of sections.

    return 1;

}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

{

    // Return the number of rows in the section.

    if([_arraycount]>0) {

        return[_arraycount];

    }else{

        return1;

    }

}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

    staticNSString*CellIdentifier =@"Cell";


    //初始化cell并指定其类型,也可自定义cell

    UITableViewCell*cell = (UITableViewCell*)[tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell ==nil)

    {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        cell.backgroundColor = [UIColor clearColor];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }

    if([_arraycount]>0) {

        NSDictionary*infoDic = [[NSDictionaryalloc]init];

        infoDic = [_arrayobjectAtIndex:indexPath.row];

        cell.textLabel.text= [NSStringstringWithFormat:@"name:%@  password:%@",[infoDicobjectForKey:@"name"],[infoDicobjectForKey:@"password"]];

    }else{

        cell.textLabel.text=@"没有数据";

    }





    returncell;

}

你可能感兴趣的:(plist 文件)