0

我正在尝试UITableView使用 plist 文件中的信息填充 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
4

1 回答 1

0

至少我希望您需要执行以下操作:

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

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

于 2013-07-30T23:28:52.113 回答