故事板有一个带有一个原型单元的tableview,UITableView有一个原型单元,它已被配置为自定义UITableViewCell子类。
原型单元正确连接到自定义sublcass,IBOutlets配置正确,但出于某种原因,当我得到单元格时,它最终所有自定义子视图都是零。
我还配置了它,以便customIdentifiers是相同的。
答案 0 :(得分:18)
所以我遇到的问题是一个奇怪的疏忽,当你在故事板中识别出一个reuseIdentifier时,你不必打电话
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier;
TableView上的。如果你这样做,这实际上将打破它打算做的功能。
当搞乱自定义UITableViewCells时,只需将reuseIdentifiers设置为通用,并且我会相信你会在幕后为registerClass做。如果你自己做,它就不会工作。
答案 1 :(得分:0)
我导入了Custom Cell类并在cellForRowAtIndexPath方法中实现我的代码,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"FixtureCustomCell";
FixtureCustomCell *cell = (FixtureCustomCell *)[fixtureTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLabelObject = [[NSBundle mainBundle] loadNibNamed:@"FixtureCustomCell" owner:self options:nil];
for (id currentObject in topLabelObject)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (FixtureCustomCell *) currentObject;
break;
}
}
}
Fixture *currentFixture = [[xmlParser fixtures] objectAtIndex:indexPath.row];
cell.dateLabel.text = currentFixture.date;
NSLog(@"%@",currentFixture.date);
cell.venueLabel.text=currentFixture.venue;
NSLog(@"%@",currentFixture.venue);
cell.firstTeamNameLabel.text=currentFixture.firstTeam;
NSLog(@"%@",currentFixture.firstTeam);
cell.secondTeamNameLabel.text=currentFixture.secondTeam;
cell.timeLabel.text=currentFixture.time;
cell.matchType.text=currentFixture.matchType;
cell.specialMatchLabel.text=currentFixture.specialMatch;
// cell.firstTeamLogoImageView.image=currentFixture.firstTeamImage;
// cell.secondTeamLogoImageView.image=currentFixture.secondTeamImage;
imageQueuefirstTeamLogo = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(imageQueuefirstTeamLogo, ^
{
UIImage *imageTVGuideLogo = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:[currentFixture firstTeamImage]]]];
dispatch_async(dispatch_get_main_queue(), ^
{
cell.firstTeamLogoImageView.image = imageTVGuideLogo;
[cell setNeedsLayout];
});
});
imageQueuesecondTeamLogo = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(imageQueuesecondTeamLogo, ^
{
UIImage *imageTVGuideLogo2 = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:[currentFixture secondTeamImage]]]];
dispatch_async(dispatch_get_main_queue(), ^
{
cell.secondTeamLogoImageView.image = imageTVGuideLogo2;
[cell setNeedsLayout];
});
});
return cell;
// Set up the cell...
}