2012-10-01 36 views
0

可能重複:
How do you load custom UITableViewCells from Xib files?如何解決Thread1:SIGABRT信號?與此行[[NSBundle mainBundle] loadNibNamed:@「DVDListingView」owner:self options:nil];

這裏是我的代碼..

// 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; 
} 

如何解決線程1:這條線[一個NSBundle mainBundle]信號SIGABRT問題loadNibNamed :@「DVDListingView」擁有者:self options:nil];

回答

1

我會建議試試這個,同時確保您「DVDListingView.xib」 是筆尖的自定義單元格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; 
} 
+0

謝謝! :)它現在的作品! :) – Aybs

0

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

返回一個NSArray 。它需要是這樣的:

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; 
     } 
    } 
} 
+0

好的謝謝!這有助於!謝謝 ! :)它現在的作品! – Aybs

相關問題