0

Possible Duplicate:
How do you load custom UITableViewCells from Xib files?

Here is my code ..

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"LibraryListingCell";

    DVDListingViewCell *cell = (DVDListingViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil];
        cell = [_cell autorelease];
        _cell = nil;
    }

    cell.titleLabel.text = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];    
    cell.featureLengthLabel.text = [NSString stringWithFormat:@"%@ minutes", 
                                    [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"featureLength"]];
    cell.coverImageView.image = [UIImage 
                                 imageNamed:[[dao libraryItemAtIndex:indexPath.row] valueForKey:@"coverImage"]];

    return cell;
}

How to solve Thread1 : Signal SIGABRT problem with this line [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil];

Community
  • 1
  • 1
Aybs
  • 1
  • 2

2 Answers2

1

I would advise to try this, while making sure that you "DVDListingView.xib" is the NIB for the custom cell ONLY

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"LibraryListingCell";

    DVDListingViewCell *cell = (DVDListingViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil];
        for(id currentObject in topLevelObjects){
            if([currentObject isKindOfClass:[DVDListingViewCell class]]){
                cell = (DVDListingViewCell *)currentObject;
                break;
            }
        }
    }

    cell.titleLabel.text = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];    
    cell.featureLengthLabel.text = [NSString stringWithFormat:@"%@ minutes", 
                                    [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"featureLength"]];
    cell.coverImageView.image = [UIImage 
                                 imageNamed:[[dao libraryItemAtIndex:indexPath.row] valueForKey:@"coverImage"]];

    return cell;
}
ibanez
  • 158
  • 1
  • 1
  • 8
0

The line

 [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil];

returns an NSArray. It needs to be like this:

NSArray *xibObjectArray =  [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil];
//retrieve items from the array
if (xibObjectArray.count == 1) {
     cell = [xibObjectArray objectAtIndex:0];
} else {
     for (UIView *randomView in xibObjectArray) {
        if ([randomView isKindOfClass:[DVDListingViewCell class]]) {
           cell = (DVDListingViewCell *)randomView;
        }
     }
}
Daddy
  • 9,045
  • 7
  • 69
  • 98