【问题标题】:How to solve Thread1 : Signal SIGABRT ? with this line [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil]; [duplicate]如何解决 Thread1:信号 SIGABRT?用这一行 [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil]; [复制]
【发布时间】:2012-09-22 14:55:12
【问题描述】:

可能重复:
How do you load custom UITableViewCells from Xib files?

这是我的代码..

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

如何解决 Thread1 : Signal SIGABRT problem with this line [[NSBundle mainBundle] loadNibNamed:@"DVDListingView" owner:self options:nil];

【问题讨论】:

    标签: iphone ios xcode ios5 ios4


    【解决方案1】:

    我建议您尝试一下,同时确保您“DVDListingView.xib”是仅用于自定义单元格的NIB

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

    【讨论】:

    • 谢谢! :) 现在可以了! :)
    【解决方案2】:

    线

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

    【讨论】:

    • 好的,谢谢!这有帮助!谢谢 ! :) 现在可以使用了!
    猜你喜欢
    • 2017-10-30
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 2010-12-14
    相关资源
    最近更新 更多