首页 > 代码库 > UITableView数据填充方式

UITableView数据填充方式

1、文件有xib或者从属的stroybord:可以对其UITableView中TableView(content)和TableViewCell(style,image,identifier,accessory)设置,改变其属性,查看其显示的状态。

2、封装成Sample.plist的格式:

   NSString *path = [[NSBundle mainBundle]pathForResource:@"SampleData" ofType:@"plist"];    

    NSArray *items = [[[NSDictionary alloc]initWithContentsOfFile:path] objectForKey:@"Data"];      

    for (NSDictionary *dict in items) {        

        BasicItem *item = [[BasicItem alloc]init];

        item.image = [UIImage imageNamed:[dict objectForKey:@"Image"]];

        item.text = [dict objectForKey:@"Place"];

        item.detailText = [dict objectForKey:@"Country"];

        [self.items addObject:item];

    }

3、可以结合NSDictionary和NSArray来进行:

 NSArray *object = [[NSArray alloc] initWithObjects:@"red",@"green",@"white",@"black",nil];    

    NSArray *key = [[NSArray alloc]initWithObjects:@"one",@"two",@"three",@"four", nil];    

    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:object,@"image", key,@"title", nil ];     

    for (id key in dict) {

        NSLog(@"key : %@, value : %@",key,[dict objectForKey:key]);

    }

UITableView数据填充方式