0

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

Picture of track trace

EDIT 2 My thread 1: THrea1

EDIT 3: I think THIS is the problem. With custom cells I get null objects :/ cell is null

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
Yannis P.
  • 811
  • 1
  • 11
  • 32
  • Please post the complete, symbolicated stack trace and the exact error message you receive. – Aaron Brager Mar 11 '15 at 23:37
  • Can you please tell me how to do that? – Yannis P. Mar 11 '15 at 23:50
  • https://stackoverflow.com/questions/15946499/xcode-full-stack-trace – Aaron Brager Mar 11 '15 at 23:51
  • 1
    Looks like you have an infinite loop. Can you expand thread 1? – Aaron Brager Mar 12 '15 at 00:05
  • Is that what you mean? – Yannis P. Mar 12 '15 at 00:23
  • is "finished" method only called once? also check for the data you received from aPastfixture. – Kris Julio Mar 12 '15 at 01:13
  • the data is correct. How can I check how many times the method gets called? It should only be called once. With the basic UITableVIewCell it worked. – Yannis P. Mar 12 '15 at 01:17
  • 1
    You see the number there to the left of "CA::Layer::ensure_transaction..."? That's how many times it's been called. You have somehow created a UIView structure that loops back on itself. – Hot Licks Mar 12 '15 at 02:17
  • I used breakpoints to find the exact point it terminates. It finishes the "- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath " execution for ALL items I added, and then it crushes. Maybe that helps? – Yannis P. Mar 12 '15 at 09:37
  • If you put a breakpoint here `cell.teamsVSTextLabel.text = matchString;`, and continue, are the cell properties being set? – Vannens Mar 12 '15 at 12:17
  • Using NSLog(@"Log1: %@", cell.teamsVSTextLabel.text); NSLog(@"Log2: %@", cell.teamsScoreDetailLabel.text) right after that line, I get the correct results, so I'm guessing the cell gets initiated afterall? – Yannis P. Mar 12 '15 at 12:42

1 Answers1

-1

Did you register the tableCell in viewDidLoad? [self.tableView registerClass:[FixtureTableViewCell class] forCellReuseIdentifier:@"pastFixtureCell"];

EDIT:

Don't forget to check if the cell is nil.

if (cell == nil) {
    cell = [[FixtureTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle @"pastFixtureCell"];
}
Vannens
  • 167
  • 1
  • 10
  • If you register a class, the cell will never be nil, so there's no need to check. Also, you should not register the class if the cell was made in a xib or storyboard. – rdelmar Mar 12 '15 at 01:03
  • WHen I registered the tablecell the app didn't crush anymore but the table also didn't get populated – Yannis P. Mar 12 '15 at 01:16
  • Oh, storyboards... So, did you change the cell custom class in the Identity Inspector to be your `FixtureTableViewCell`? Maybe that's the reason it crashed in the first place? http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/5264cfdde4b070b299b2b0f4/5264cfe0e4b070b299b2b3c8/1357213449000/?format=300w – Vannens Mar 12 '15 at 12:11
  • yes I did and I'm using the correct reuseIdentifier ;) – Yannis P. Mar 12 '15 at 12:33