如何从UITableViewCell获取其他控件值?
我有一个疑问,当我们在自定义 tableViewCell 时选择一行或点击按钮时如何获取其他控件的值。 假设我有一个带有 TextField、滑块和按钮的 TableView Cell。按钮的操作使用:
btn.tag = indexPath.row;
[btn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
现在我可以在其操作方法上获取按钮。我需要在点击按钮时获取文本字段的值和滑块的值。
一个选项是我创建一个数组并将这两个控件的值存储在该数组中并对其进行管理。但我认为这不是正确的管理方法。
请引导我找到获取 UITableViewCell 子视图值的正确方法。
谢谢
I have one doubt that how to get other control's value when we select a row or tap on button while having custom tableViewCell.
Suppose I have a TableView Cell with a TextField, a Slider and button. Button has action using:
btn.tag = indexPath.row;
[btn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
Now I can get button on its action method. I need to get textField's value and slider's value on button tap.
The one option is I create a array and store values for these two control in that array and manage this. But I don't think this is correct way to manage it.
Please navigate me to the currect way to get value of UITableViewCell's subview's value.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建文本字段和滑块时,给它们一个常量标签,然后添加到单元格的 contentView 中
,然后添加到您的 buttonTapped: 方法中
While creating your textfield and slider, give them a constant tag and then add to cell's contentView
and then in your buttonTapped: method
每当您为
UITableViewCell
创建子视图(按钮、文本字段等)时,请不要忘记标记它们。标记后,您可以使用以下方法访问它们。
当您选择时,您可以使用
UIView
的ViewWithTag
函数获取UITableViewCell的子视图。Whenever you create subviews (button , text field etc. ) for your
UITableViewCell
don't forget to tagged them.Once you tagged, you could access them using below method.
When you select,you could get the subviews of your UITableViewCell's by using
ViewWithTag
function ofUIView
.