我无法让我的CustomTableViewCell
,UITableViewCell
的子类出现在我的表格视图中。使用XIB文件加载UITableViewCell子类
我使用xib来表示该单元格,但我假设数据源委托的代码不会更改。我确保在表格视图单元格XIB中设置一个相同的重用标识符。
我找出问题的事实,即返回表格单元格的数据源的方法不能正常工作,那就是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
DataObject *foo = [self.dataArray objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[[cell overview] setText:foo.overview];
[[cell price] setText:foo.price];
NSLog(@"cell initialized, description text is %@",cell.overview.text);
return cell;
}
不知道为什么,这是行不通的,但最后的日志语句总是在最后打印一个(null),而且我确实证实数据对象的overview
属性在其中有一个有效的字符串。 price
同样的事情。
http://stackoverflow.com/questions/4195726/how-to -create-custom-tableviewcell-from-xib试试!!!我认为你的答案在那里! – trumpetlicks
是的,它可以工作,但是当我在前几次尝试该方法时遇到了异常,请参阅我对如何避免接受的答案的评论。 –
嘿@AndrewLauerBarinov,所以我在同一个问题atm,但我用故事板代替。想知道您对接受答案的评论,我似乎并不明白“IBOutlet与您所说的视图不是文件所有者”的关系。对不起,我有点新与ios,所以我仍然试图学习我需要做的连接和东西方面的东西。你能请进一步解释一下吗?谢谢!还在这里发布的东西http://stackoverflow.com/questions/15175472/custom-uitableviewcell-will-not-display-label-texts – gdubs