I'm created a custom table view cell
@interface FixtureTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *teamsVSTextLabel;
@property (weak, nonatomic) IBOutlet UILabel *teamsScoreDetailLabel;
@end
I make an asynchronous request to a server for data, and when it returns I reload the tables data. This is my
//reload table data when request is over
-(void)finished
{
self.pastFixturesArray = aPastFixture.pastFixturesArray;
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FixtureTableViewCell *cell = (FixtureTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"pastFixtureCell" forIndexPath:indexPath];
// Configure the cell...
PastFixture *thisFixture = [pastFixturesArray objectAtIndex:indexPath.row];
//string to store the match result and score result
NSMutableString *matchString = [[NSMutableString alloc] init];
NSMutableString *matchScoreString = [[NSMutableString alloc] init];
//configure match string
[matchString appendFormat:@"%@ vs %@",thisFixture.homeTeam.teamName, thisFixture.awayTeam.teamName];
//configure the score string
[matchScoreString appendFormat:@"%ld - %ld", thisFixture.homeScore, thisFixture.awayScore];
//configure cell labels
cell.teamsVSTextLabel.text = matchString;
cell.teamsScoreDetailLabel.text = matchScoreString;
cell.teamsScoreDetailLabel.textColor = [UIColor blueColor];
return cell;
}
The custom cell works if I populate the table when the view first loads and I don't reload the table data, and it also works if I don't use custom cells, so the problem is specific to reloading my table with custom cells. Can someone help please?
EDIT And I'm getting an EXC_BAD_ACCESS code=2 error message, so it's probably something to do with memory
EDIT 2 My thread 1:
EDIT 3: I think THIS is the problem. With custom cells I get null objects :/
Here is my custom cell's implementation file:
#import "FixtureTableViewCell.h"
@implementation FixtureTableViewCell
@synthesize teamsVSTextLabel, teamsScoreDetailLabel;
- (void)awakeFromNib {
// Initialization code
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
teamsVSTextLabel.text = @".";
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end