简体   繁体   English

表格视图未使用原型单元

[英]Prototype Cell not being used by tableview

I have read many posts about similar problems but nothing seems to work, I am obviously doing something wrong. 我读过许多有关类似问题的文章,但似乎无济于事,我显然做错了什么。 I have a TableViewController that is in a StoryBoard (XCode 5). 我在StoryBoard(XCode 5)中有一个TableViewController。 For the PrototypeCell I set the type to custom and set the Identifier to "pbvcell". 对于PrototypeCell,我将类型设置为custom,并将标识符设置为“ pbvcell”。 I added some labels, changed the background etc.. Here is my tableview delegate method for setting the cell 我添加了一些标签,更改了背景等。这是用于设置单元格的tableview委托方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pbvcell"];


// Configure the cell...

PBVlead *lead = [self.leads objectAtIndex:indexPath.row];
NSLog(@"Cell class %@", [cell class]);

UILabel *leadNameLabel = (UILabel *)[cell viewWithTag:1];
leadNameLabel.text = lead.leadName;
return cell;
}

Now the app launches but even after I add an object to the tableview datasource array and do a reload data, the cells are blank, like the custom cell is not being used. 现在,该应用程序启动,但是即使在我将一个对象添加到tableview数据源数组并执行重新加载数据后,这些单元格还是空白的,就像未使用自定义单元格一样。 It looks like this should be easy and thats all I need to do. 看起来这应该很简单,这就是我需要做的所有事情。 What on earth am I missing? 我到底想念什么?

I left this in a comment above but just to keep things tidy I will post it as an answer here. 我在上面的评论中保留了此内容,但为了使内容整洁,我将其发布为答案。 It is silly but it is good to note that you have to manipulate the contextView of a prototype cell and not the tableview cell itself in order for your visual changes to have an effect... 这很愚蠢,但要注意,您必须操纵原型单元的contextView而不是tableview单元本身,才能使视觉更改生效。

"Because I embrace my own stupidity I will tell everyone what was going on here. I had set the TableCell background to blue and added some UILabels and set there color to white to show up against the blue background. Run the app, no labels.... What I finally realized is, I had not set the Content View background to blue. So..... What was happening was the labels actually are shown in the content view in the view hierarchy. White labels on a white background equals, invisible... :-) I set the content view background to blue and wola, there is everything! :-) Brother..? “因为我怀有自己的愚蠢,所以我将告诉大家这里发生了什么。我已经将TableCell背景设置为蓝色,并添加了一些UILabels,并将其中的颜色设置为白色以在蓝色背景下显示。运行该应用程序,没有标签。 ...我终于意识到,我没有将Content View背景设置为蓝色。所以.....发生的是标签实际上显示在视图层次结构的Content视图中。等于,不可见... :-)我将内容视图背景设置为蓝色和紫色,什么都有!:-)兄弟..?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM