简体   繁体   English

将自定义UITableViewCell与原型单元格一起使用

[英]Using a Custom UITableViewCell with Prototype Cells

For reference, this tutorial I am following: http://mobile.tutsplus.com/tutorials/iphone/customizing-uitableview-cell/ 作为参考,我正在关注本教程: http : //mobile.tutsplus.com/tutorials/iphone/customizing-uitableview-cell/

I have to create a custom UITableViewCell, and from the tutorial, it said to leverage Prototyping cells and subclass UITableViewCell. 我必须创建一个自定义UITableViewCell,并从本教程开始,它要利用原型单元和UITableViewCell的子类。 Then connect the UI elements in the prototype cel to the custom class (of UITableViewCell). 然后将原型cel中的UI元素连接到(UITableViewCell的)自定义类。

The problem I am running into here is, there is only one cell for the whole table view that is displaying data. 我在这里遇到的问题是,整个表视图中只有一个单元格正在显示数据。 However, I am able to click on empty cells in the background behind that one cell that contains data. 但是,我可以在包含数据的一个单元格后面的背景中单击空白单元格。 If i scroll up or down, cellForRowAtIndexPath is called and another cell gets displayed. 如果我向上或向下滚动,将调用cellForRowAtIndexPath并显示另一个单元格。 However its only displaying once cell at a time for the whole table view. 但是,整个表格视图一次只显示一个单元格。

在此处输入图片说明

Does anyone know what the problem could be here? 有人知道问题可能在这里吗? Any help is appreciated, thanks! 任何帮助表示赞赏,谢谢!

Figured out what the problem is, my labels (that are supposed to be inside the custom prototyping cell) were added to the parent view and not the content view of UITableViewCell. 找出问题所在,将我的标签(应该在自定义原型单元中)添加到了父视图,而不是UITableViewCell的内容视图。 This is because my prototype cell did not have a content view for some reason. 这是因为我的原型单元出于某种原因没有内容视图。 I had to add a another prototype cell and delete the previous one. 我必须添加另一个原型单元并删除之前的单元。

reference: How to add subviews to a custom UITableViewCell in a storyboard 参考: 如何在情节提要中将子视图添加到自定义UITableViewCell

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

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