如何通知视图控制器已在 UIPickerView 中选择了一行?
当在 UIPickerView
中选择一行时,如何通知我的视图控制器并向其传递字符串?
我在常规视图中有一个自定义 UIPickerView
,并且在不同的类中有一个自定义数据源/委托。
如何在 pickerView:didSelectRow:inComponent:
委托方法期间通知我的视图?并将选定的字符串传递给视图控制器?
How do I notify my view controller and pass it the string when a row was selected in my UIPickerView
?
I have a custom UIPickerView
in regular view and I have a custom datasource/delegate in a different class.
How do I notify my view during the pickerView:didSelectRow:inComponent:
delegate method? and pass the selected string to the view controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
符合选择器委托的类将实现
以了解在选择器中选择了哪一行(或字符串)。
如果外部世界的某个其他类想知道选择了哪一行,那么该类又需要通知。这将创建一个授权链。
例如,如果 pickerClass 是实现委托方法的类。如果其他一些类(比如outsideClass)想要知道选择了哪一行,那么您可以创建pickerClass的outsideClass委托并将此消息传递给它。
The class that is conforming to the picker delegates would implement
to know which row (or string) was selected in the picker.
If some other class from the outside world wants to know which row was selected, then this class in turn needs to inform. This will create a chain of delegation.
For example, if pickerClass is the class that implements the delegate method. If some other class (say outsideClass) wants to know about which row was selected, then you would make this outsideClass delegate of pickerClass and pass on this message to it.
为此,您必须在自定义类中创建一个方法,如下所示:
.h 文件
父母身份证;
.m 文件
然后您以编程方式设置委托方法,如下所示:
uipickerview.delegate = 父级;
uipickerview.datasource = 父级;
希望它会有所帮助。
如果有困难请告诉我。
For that, you have to create one method in custom class like below:
.h file
id parent;
.m file
Then you have set the delegate method programatically like below:
uipickerview.delegate = parent;
uipickerview.datasource = parent;
Hope it will be helpful.
Let me know in case of difficulty.
您可以通过使用 NSNOtification centet 发布和观察通知或创建委托协议来完成此操作。研究委托协议,这是在 Objective-C 中学习的一件好事。
You can do this by either using posting and observing notification using NSNOtification centet or by creating a delegate protocol. Study delegate protocols that is a good thing to learn in objective-c.