这里有点奇怪的问题:
我有一个自定义笔尖UITableViewCell
,带有一堆标签和一个imageview。我将文件所有者设置为UITableViewDelegate
/ Datasource
,我在nib文件中设置自定义类,然后将其加载到我的VC中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BuildCell";
BuildCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"BuildCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
...
return cell
}
奇怪的是,每当我将cellIdentifier设置为与故事板中的ID不同时,一切都很好(但这是一个问题,因为我不能让segue正常工作)。当我将单元格标识符设置为匹配时,只有部分属性可以正常工作。怎么会这样?
这是cellForRowAtIndexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BuildCell";
BuildCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"BuildCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
Build *build = [self.builds objectAtIndex:indexPath.row];
//cell.school.text = build.school;
cell.device.text = build.sdk;
cell.buildType.text = build.config;
cell.creator.text = [NSString stringWithFormat:@"By %@", build.creator];
cell.time.text = build.dateCreated;
switch (build.buildStatus) {
case kSuccess:
cell.imageView.image = [UIImage imageNamed:@"greensmall.png"];
break;
case kInProgress:
cell.imageView.image = [UIImage imageNamed:@"yellowsmall.png"];
break;
default:
cell.imageView.image = [UIImage imageNamed:@"redsmall.png"];
break;
}
return cell;
}
正确加载的唯一部分是imageView。没有标签出现。有什么想法吗?