没有图像显示使用plist填充UITableview自定义单元格

时间:2013-07-30 20:45:52

标签: iphone ios uitableview plist custom-cell

我正在尝试使用plist文件中的信息在UITableView中填充2个图像。

目前我的所有标签字段都在填充,但是我没有显示任何图像。由于我是新手,我不太清楚图像代码有什么问题,我不知道从这里去哪里。任何帮助整理图像代码行,以便在UITableview中填充图像将不胜感激。

我的代码如下:

#import "ViewController.h"
#import "MenuViewCell.h"

@interface ViewController ()

@property (copy, nonatomic) NSArray* tableData;

@end

@implementation ViewController


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableData = [NSArray arrayWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"TestList" ofType: @"plist"]];
    NSLog(@"%@",_tableData);

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:(BOOL)animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [_tableData count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    //return [[[_tableData objectAtIndex: section] objectForKey: @"Rows"] count];
    NSDictionary *dataInSection = [[_tableData objectAtIndex: section] objectForKey: @"Rows"];
    return [dataInSection count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    return [[_tableData objectAtIndex: section] objectForKey: @"Title"];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"MenuCell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSDictionary *sectionData = _tableData[indexPath.section];
    NSArray *rowsData = sectionData[@"Rows"];
    NSDictionary *rowData = rowsData[indexPath.row];


    UILabel *homeLabel = (UILabel *)[cell viewWithTag:100];
    homeLabel.text = rowData[@"home"];

    UILabel *homeScoreLabel = (UILabel *)[cell viewWithTag:101];
    homeScoreLabel.text = rowData[@"homeScore"];

    UILabel *awayLabel = (UILabel *)[cell viewWithTag:102];
    awayLabel.text = rowData[@"away"];

    UILabel *awayScoreLabel = (UILabel *)[cell viewWithTag:103];
    awayScoreLabel.text = rowData[@"awayScore"];

    UIImageView *homeImage = (UIImageView *)[cell viewWithTag:104];
    homeImage.image = rowData[@"homeImage"];


    UIImageView *awayImage = (UIImageView *)[cell viewWithTag:105];
    awayImage.image = rowData[@"awayImage"];

    return cell;
}

- (void)dealloc {
    [_tableData release];
    [super dealloc];
}
@end

1 个答案:

答案 0 :(得分:0)

我希望你至少需要做一些事情:

homeImage.image = [UIImage imageWithData:[rowData [@“homeImage”]];

您是否通过调试检查了_tableData是否以您期望的方式包含了plist的内容?