正在发布的自定义 UITableViewCell 对象 - Xcode 4.2 中的原型单元

发布于 2024-12-29 05:35:12 字数 553 浏览 3 评论 0原文

我有一个自定义 UITableViewCell 子类和一个我想要插入文本框的表视图控制器。

我所做的是设置一个三维数组来存储部分、行,然后在第三维中放置我想要显示的占位符文本 -

在自定义 UITableViewCell 子类中,我将文本框定义为弱属性(我认为这是正确的...?)

@property (weak) IBOutlet UITextField *plainTextField;

然后我将此文本字段添加到我的数据模型数组中,

cellForRowAtIndexPath:

但是,当我尝试从我的数组(特别是 plainTextField.text)访问文本字段时,我感觉

''

有些东西正在被在某个地方发布,我不明白其中(实际的文本字段不为零)

我想,我的问题实际上是一个设计问题——如何将 UITextFields 放入 UITableViewController 中,然后稍后从中取出文本......?

谢谢!

I have a custom UITableViewCell subclass, and a table view controller which I want to insert text boxes into.

What I have done is setup a three dimensional array to store the sections, rows and then in the third dimension I have put the placeholder text I would like to display -

In the custom UITableViewCell subclass I have defined the text box as a weak property (I think this is correct...?)

@property (weak) IBOutlet UITextField *plainTextField;

I then add this text field to my data model array in

cellForRowAtIndexPath:

however, when I try to access the textfield from my array (specifically plainTextField.text) I get

''

I get the feeling that something is being released somewhere and I can't figure out where (the actual textfield is not nil)

I guess, my question is really a design one -- how do you get UITextFields into a UITableViewController and then get the text out of them later....?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅刃 2025-01-05 05:35:12

我已经“修复”了我的问题——这实际上是基于这样一个事实:UITableViewCells 中不能有不同的内容,一旦有任何不同,您就必须将其加载到 cellForRowAtIndexPath 中。 (UITableViewCell prepareForReuse 方法中的注释)

我所做​​的是在数据模型中为 UITextField 保留一个位置,然后当 cellForRowAtIndex 路径到达单元格时,它将查询数据模型,然后实例化一个 UITextField 并将其添加到 < code>cell.contentView 或(这是棘手的部分)循环通过 [cell.contentview subviews] 查找任何 UITextFields 并调用removeFromSuperview

I've 'fixed' my problem -- it's really based on the fact that you can't have different content in UITableViewCells, as soon as anything is different you have to load it in cellForRowAtIndexPath. (A note in the UITableViewCell prepareForReuse method)

What I did was reserve a spot in my data model for a UITextField, and then when cellForRowAtIndex path got to the cell it would query the data model, then instantiate a UITextField and add it to the cell.contentView or (here's the tricky part) loop through [cell.contentview subviews] to find any UITextFields and call removeFromSuperview

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文