iPad 和 UIPickerView(或 UIDatePickerView)
有人在 3.2 SDK 中使用过 UIPicker 吗?我正在将 iPhone 应用程序移植到 iPad,但这是我无法开始工作的一件事。我已经尝试过...
-创建一个操作表,将选择器添加为子视图并显示它。
-创建上面的操作表,使其成为通用 ViewController 的视图,将该 VC 添加到 UIPopover
-仅使选择器成为通用 ViewController 的视图,将该 VC 添加到 UIPopover
使用操作表,它甚至不会尝试来画它。在弹出视图中,它尝试绘制但未正确渲染。
只是想检查一下是否有人已完成此操作以及如何完成。
谢谢大家!
Has anyone had any luck using a UIPicker in the 3.2 SDK? I'm in the middle of porting an iPhone application over to an iPad and that's the one thing I can't seem to get to work. I've tried...
-Creating an action sheet, add the picker as a subview and displaying it.
-Creating that above action sheet, making it the view of a generic ViewController, adding that VC to a UIPopover
-Making just the picker the view of a generic ViewController, adding that VC to a UIPopover
With the action sheet it doesn't even attempt to draw it. In the popover view it attempts to draw but doesn't get rendered correctly.
Just wanted to check to see if anyone has accomplished this and if so how.
Thanks everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我为此奋斗了大约 24 小时,并通过遵循本教程让它开始工作,无论他在哪里提到他的 UITableView,只需考虑您的 UIPickerView 并替换适当的信息即可。
Matthew Casey - 教程:iPad 上的 Pop Over 控件简介
简而言之,在 iPad 上,显示选择器的唯一方法是在 Popover 控件内。我无法弄清楚在弹出窗口的内容视图控制器(选择器视图的视图控制器)和主应用程序的视图控制器之间共享数据。 (即让选取器的“didSelectRow”方法影响主视图控制器中的对象,例如 UITextField 或 UIButton。)这是通过创建自定义协议将“didSelectRow”方法转发到主视图控制器来处理的。
我绝不是这方面的专家,所以我一步一步地学习了该教程,最终它确实起作用了。在我找到该教程之前,我迷失了方向。 (我还将 iPhone 应用程序移植到 iPad。)
I just struggled with this for about 24 hours and got it to work by following this tutorial and wherever he mentions his UITableView, just think about your UIPickerView and replace the appropriate info.
Matthew Casey - Tutorial: Introduction to Pop Over Control on iPad
In short, on the iPad, the ONLY way you can show a picker is inside a popover control. Sharing data between the popover's content view controller (the picker view's view controller) and the main app's view controller is the bit I couldn't figure out. (i.e. getting the picker's "didSelectRow" method to affect an object in your main view controller, say a UITextField or UIButton.) This is handled by creating a custom protocol to forward the "didSelectRow" method to the main view controller.
I'm by no means an expert at this stuff, so I went step by step with that tutorial and it DID work in the end. Before I found that tutorial I was lost. (I am also porting over an iPhone app to iPad.)
我是上述教程的作者。要使选择器在弹出窗口中工作并将所选值添加到主视图中的文本框,您需要使用协议。我创建了一个示例项目来展示这一点。我将很快创建一个关于此的教程。
示例项目
I am the author of the tutorial mentioned above. For a picker to work in a popover and add the selected value to the textbox in the main view you need to use protocols. I have created a sample project to show this. I will be creating a tutorial on this soon.
Sample Project
当你想在视图控制器之间共享数据时......解决方案是 NSNotificationCenter。
我知道这并不能完全回答问题,但如果我想在视图控制器之间共享数据:
在发送视图控制器中
在接收视图控制器中:
放置在 viewDidLoad 中
,然后添加此函数:
这适用于在 2 个视图控制器之间共享数据……好吧,无论如何,数据量很小。
否则,请在此处查看有关在视图控制器之间共享数据
When you want to share data between view controllers ... the solution is the NSNotificationCenter.
I know this doesn't answer the question in whole, but if I want to share data between view controllers:
In the sending view controller
In the receiving view controller:
Place in the viewDidLoad
then add this function:
This works for sharing data between 2 view controllers... well, small amounts of data anyways.
Otherwise look here for more about sharing data between view controllers
您使用界面生成器吗?在 Xcode 中使用 nib 文件创建一个新的 UIViewController 子类,然后拖入 UIPicker 会容易得多。然后您需要在弹出窗口中呈现视图控制器。操作表未设计为具有子视图,因此不要这样做。
我已经做到了:请参阅 C64 Paint 中的第三个屏幕截图。
Are you using Interface Builder? It's a lot easier to create a new UIViewController subclass in Xcode with the nib file, and then drag in the UIPicker. Then you need to present the view controller in a popover. Action sheets are not designed to have subviews, so don't do that.
I have done it: see the third screenshot in C64 Paint.
谢谢大家的回复。因此,虽然我不能说最初的问题是什么,但我从头开始解决这个问题并让它发挥作用。我制作了全新的视图控制器并将它们显示在弹出窗口中,效果很好。似乎是制作通用应用程序的难点之一。
Thanks for the responses everyone. So while I can't say what the initial problem was, I started the problem from scratch and got it to work. I made completely new View Controllers and displayed them in a Popover and it worked well. Seems to be one of the tougher points of making a universal app.
如果您在 iPad 上创建它,则 UIPickerView 将可以工作,如果您像这样创建它:
其他一些尺寸似乎也可以工作。但 CGRectZero 无法在 iPad 上运行——尽管它可以在 iPhone 上运行。
The UIPickerView will work if you create it on the iPad if you create it like so:
Some other sizes do appear to work. But CGRectZero does not work on the iPad -- even though it does work in the iPhone.