I am trying to populate 2 images in a UITableView
with information from a plist file.
Currently all of my label fields are populating however I am getting no images are showing. As I am new to this I am not quite sure whats wrong with the image code and I do not know where to go to from here. Any help to sort out the image code lines so the images populate in the UITableview
would be appreciated.
My code is as follows:
#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