Hi,
I get my table to show up, but the info isnt populated properly.
The cell just shows the text i have put in as a placeholder and not what is in my plist.
this works
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
if (CurrentLevel == 0) {
NSMutableArray *array = [[NSMutableArray alloc] init];
self.bandList = array;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.bandList = [appDelegate.data objectForKey:@"Rows"];
self.navigationItem.title = @"2012 Competing Bands";
}
else
self.navigationItem.title = CurrentTitle;
}
this works
Code:
- (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.
return [bandList count];
}
this partially works, the images that show up are correct but the title and description dont show
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:@"BandCell"];
// Configure the cell...
NSDictionary *dict = [self.bandList objectAtIndex:indexPath.row];
cell.nameLabel.text = [dict objectForKey:@"Title"];
cell.countryLabel.text = [dict objectForKey:@"Description"];
UIColor *color = ((indexPath.row % 2) == 0) ? [UIColor colorWithRed:0/255 green:0/255 blue:0/255 alpha:1] : [UIColor blackColor];
cell.nameLabel.textColor = color;
//adding image to cell
if ([dict objectForKey:@"imageKey"] == nil) {
return cell;
} else {
NSString *path = [[NSBundle mainBundle] pathForResource:[dict objectForKey:@"imageKey"] ofType:@"png"];
UIImage *theImage = [UIImage imageWithContentsOfFile:path];
cell.imageView.image = theImage;
theImage = cell.bandImage.image;
theImage = nil;
}
return cell;
}
Here is the table Cell file
Code:
// TableCell.h
#import <UIKit/UIKit.h>
@interface TableCell : UITableViewCell
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *countryLabel;
@property (nonatomic, strong) UIImageView *bandImage;
@end
Code:
// TableCell.m
#import "TableCell.h"
@implementation TableCell
@synthesize nameLabel, countryLabel, bandImage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
I am sure i am missing something simple. I had it working before i made a custom cell but now its not. I am using a custom cell because I want the image to be there too. Can I have an image if I choose the title/subtitle cell?
Thanks for your help
CanDev