为什么我无法导入 UITableViewCell 子类?这很奇怪

发布于 2024-08-29 08:28:41 字数 1200 浏览 4 评论 0原文

是这样的,我创建了一个名为 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;
}

贾森

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人如玉 2024-09-05 08:28:41

如果此代码

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,因为 cell 可能会使编译器感到困惑。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文