Ios 表格视图显示空白的单元格
我在.xib中有一个表视图单元格。我在.xib中有一个UILabel和UIImageViewIos 表格视图显示空白的单元格,ios,parsing,cell,tableviewcell,Ios,Parsing,Cell,Tableviewcell,我在.xib中有一个表视图单元格。我在.xib中有一个UILabel和UIImageView - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { SchoolsTableViewCell *cell = (SchoolsTableViewCell *) [[[NSBundle
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
SchoolsTableViewCell *cell = (SchoolsTableViewCell *) [[[NSBundle mainBundle] loadNibNamed:@"SchoolsTableViewCell" owner:self options:nil] lastObject];
NSLog(@"Before: %@", cell.nameLabel.text);
cell.nameLabel.text = [NSString stringWithFormat:@"Name: %@", [object objectForKey:@"name"]];
NSLog(@"After: %@", cell.nameLabel.text);
PFFile *file = [object objectForKey:@"logo"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error)
{
cell.logoImageView.image = [UIImage imageWithData:data];
}];
return cell;
}
正如您所看到的,我有两个NSLog(),正在打印以下内容:
2015-07-08 20:17:26.739 o [1871:108786] Before: (null)
2015-07-08 20:17:26.740 o [1871:108786] After: Name: SMSAS
这是意料之中的
然而,在我的模拟器上,我只能看到一个名为的空白单元格。它应该在标签中显示SMSA,并加载一个徽标,但它不会发生。当点击单元格时,我可以将对象传递给下一个视图控制器,它可以显示在该视图控制器中
这是我的手机号码
@implementation SchoolsTableViewCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.nameLabel = [[UILabel alloc] init];
self.logoImageView = [[UIImageView alloc] init];
[self.contentView addSubview:self.nameLabel];
[self.contentView addSubview:self.logoImageView];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
@end
我相信这是一个简单的错误。有人愿意帮我睁开眼睛吗?谢谢 使用
dequeueReusableCellWithIdentifier
static NSString * CellIdentifier = @"SchoolsTableViewCell";
SchoolsTableViewCell *cell = (SchoolsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SchoolsTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
谢谢你,阿什,但那没用。我对以下内容进行了评论,但仍然没有解决问题:(SchoolsTableViewCell*cell=(SchoolsTableViewCell*)[[NSBundle mainBundle]loadNibNamed:@“SchoolsTableViewCell”所有者:self-options:nil]lastObject];嗯,我不知道您做了什么更改,但更新的代码似乎没有帮助。@EuwingTham
NSArray*nib=[[NSBundle mainBundle]loadNibNamed:@“SchoolsTableViewCell”所有者:自选项:nil];单元格=[nib objectAtIndex:0];
我在.xib:自定义类:SchoolsTableViewCell模块的以下区域中有SchoolsTableViewCell,是否为空?标识恢复ID:SchoolsTableViewCell表视图单元格:SchoolsTableViewCell@EuwingTham您对[self.contentView addSubview:self.namelab]的操作
?您还没有设计单元格?我还应该提到,我已经连接了引用插座。我已经将表视图单元格标识符设置为SchoolsTableViewCell。