views:

32

answers:

1

It's like this, I created a UITableViewCell subclass called NewsItemCell, then I wanna use it in my FirstViewController.m, then I tried to import it, but the compiler keeps telling me this

Below is my code, it is driving me mad, thank you if you can help.

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

Jason

A: 

Should this code

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

not be

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

and NewsItemcell *cell be NewsItemcell *newsItemCellView, as cell may confuse the compiler.

jrtc27
Thanks for you help, in fact, I mistakenly typed the NewsItemcell, it should be NewsItemCell, thanks anyway.
no problem. glad the problem was fixed :)
jrtc27