对同一选择器使用不同的委托方法?
我试图创建一个包含两个选择器的视图,每个选择器都有多个组件,其中一个选择器有 4 个基于文本的组件,另一个有两个需要显示图形的组件和两个需要显示文本的组件。有没有办法对同一选择器使用 pickerView:titleForRow:forComponent:(NSInteger)component 委托方法和 pickerView:viewForRow:forComponent:reusingView: 委托方法? 我已经实现了两者,似乎只有 viewForRow 被调用。我是否需要只使用该视图并为每一行创建一个带有标签的视图?
Im trying to create a view with two pickers, each with multiple components, one of the pickers has 4 components that are all text based, the other has two components that need to display graphics and two that need to display text. Is there any way to use the pickerView:titleForRow:forComponent:(NSInteger)component delegate method and the pickerView:viewForRow:forComponent:reusingView: delegate method for the same picker?
I've implemented both, only the viewForRow one seems to ever get called. Do I need to just use that one and create a view with a label for each row?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个选择器,是的,或者您可以为两个选择器实现一种通用方法,并通过检查其标签来确定哪个选择器正在调用它。
You can create one picker, yes, or you can implement one common method for both pickers and determine what picker is calling it by checking it's tag.
我想到的解决方案是从 pickerView:viewForRow:forComponent:reusingView: 调用 pickerView:titleForRow:forComponent: 并使用第一个方法中的字符串创建一个 UILabel 。它有效,但似乎应该有更好的方法。
The Solution I cam up with was to call pickerView:titleForRow:forComponent: from pickerView:viewForRow:forComponent:reusingView: and create a UILabel with the string from the first method. It works, but it seems like there ought to be a better way.