在故事板中使用自定义tableviewcell时,IBOutlet是零

故事板具有一个原型单元格的tableview,UITableView有一个原型单元格,并且已经被configuration为自定义的UITableViewCell子types。

原型单元格正确地连接到自定义sublcass,IBOutletsconfiguration正确,但由于某种原因,当我得到单元格它结束了我所有的自定义子视图是零。

我也configuration它,使customIdentifiers是相同的。

所以我面临的问题是一个奇怪的疏忽,当你在故事板中确定一个重用的标识符时,你不必打电话

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier; 

在TableView上。 如果你这样做,这实际上会打破它打算做的function。

当弄乱自定义的UITableViewCells时,只需要设置reuseIdentifiers是通用的,并且会在后台执行registerClass。 如果你自己做,它将无法工作。

我导入了自定义单元格类,并在下面的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... }