为什么我无法导入 UITableViewCell 子类?这很奇怪
是这样的,我创建了一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果此代码
不是,
并且
NewsItemcell *cell
为NewsItemcell *newsItemCellView
,因为 cell 可能会使编译器感到困惑。Should this code
not be
and
NewsItemcell *cell
beNewsItemcell *newsItemCellView
, as cell may confuse the compiler.