[英]Table View Cells showing blanks
我在.xib中有一個表格視圖單元格。 我在.xib中有一個UILabel和UIImageView。
- (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;
}
如您所見,我有2個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
這是預期的。
但是,在我的模擬器上,我只能看到帶有Name:的空白單元格。 它應該在標簽中顯示SMSAS,並加載徽標,但這沒有發生。 輕按單元格時,可以將對象傳遞給下一個View Controller,並且可以在該View Controller中顯示該對象。
這是我的單元格.m。
@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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.