为什么我不能导入UITableViewCell子类?那真是怪了

时间:2010-04-19 06:50:53

标签: import uitableview controller subclass

就像这样,我创建了一个名为NewsItemCell的UITableViewCell子类,然后我想在我的FirstViewController.m中使用它,然后我尝试导入它,但编译器一直告诉我这个

以下是我的代码,它让我很生气,谢谢你,如果你可以提供帮助。

#import "NewsItemCell.h"

#import "FirstViewController.h"



@implementation FirstViewController
@synthesize computers;


- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"NewsItemCellIdentifier";

    NewsItemcell *cell = (NewsItemcell *)[tableView 
                                      dequeueReusableCellWithIdentifier: CellIdentifier];
    if (cell == nil)  
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewsItemCell" 
                                                     owner:self options:nil];
        for (id oneObject in nib)
            if ([oneObject isKindOfClass:[NewsItemcell class]])
                cell = (NewsItemcell *)oneObject;
    }
    NSUInteger row = [indexPath row];
    NSDictionary *rowData = [self.computers objectAtIndex:row];
    cell.newsTitle.text = [rowData objectForKey:@"Color"];
    cell.newsDate.text = [rowData objectForKey:@"Name"];
    return cell;
}

杰森

1 个答案:

答案 0 :(得分:0)

这个代码应该

if (cell == nil)  
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewsItemCell" 
                                                 owner:self options:nil];
    for (id oneObject in nib)
        if ([oneObject isKindOfClass:[NewsItemcell class]])
            cell = (NewsItemcell *)oneObject;
}

不是

if (cell == nil)  
{
    [[NSBundle mainBundle] loadNibNamed:@"NewsItemCell" 
                                                 owner:self options:nil];
    cell = newsItemCellView
}

NewsItemcell *cellNewsItemcell *newsItemCellView,因为单元格可能会混淆编译器。