Loading a UITableView From A Nib
Posted
by Garry
on Stack Overflow
See other posts from Stack Overflow
or by Garry
Published on 2010-04-01T17:38:57Z
Indexed on
2010/04/01
17:43 UTC
Read the original article
Hit count: 387
Hi,
I keep getting a crash when loading a UITableView. I am trying to use a cell defined in a nib file.
I have an IBOutlet defined in the view controller header file:
UITableViewCell *jobCell;
@property (nonatomic, assign) IBOutlet UITableViewCell *jobCell;
This is synthesised in the implementation file.
I have a UITableViewCell created in IB and set it's identifier to JobCell.
Here is the cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"JobCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"JobsRootViewController" owner:self options:nil];
cell = jobCell;
self.jobCell = nil;
}
// Get this job
Job *job = [fetchedResultsController objectAtIndexPath:indexPath];
// Job title
UILabel *jobTitle;
jobTitle = (UILabel *)[cell viewWithTag:tagJobTitle];
jobTitle.text = job.title;
// Job due date
UILabel *dueDate;
dueDate = (UILabel *)[cell viewWithTag:tagJobDueDate];
dueDate.text = [self.dateFormatter stringFromDate:job.dueDate];
// Notes icon
UIImageView *notesImageView;
notesImageView = (UIImageView *)[cell viewWithTag:tagNotesImageView];
if ([job.notes length] > 0) {
// This job has a note attached to it - show the notes icon
notesImageView.hidden = NO;
}
else {
// Hide the notes icon
notesImageView.hidden = YES;
}
// Job completed button
// Return the cell
return cell;
}
When I run the app - I get a hard crash and the console reports the following:
objc[1291]: FREED(id): message style sent to freed object=0x4046400
I have hooked up all the outlets in IB correctly. What is the issue?
Thanks,
© Stack Overflow or respective owner