iOS 5:如何使用 UIPickerView 创建 UIAlertView? (iPhone / iPad)

发布于 2024-12-27 01:30:05 字数 287 浏览 4 评论 0原文

我需要一种允许用户从列表中选择选项的方法,我正在考虑在 UIAlertView 中使用 UIPickerView 。但是我想知道是否

  1. 可以:在 iOS 5 中轻松地将 UIPickerView 放入 UIAlertView 中(如果是这样,苹果会不赞成吗?) ;应用程序会被拒绝吗?)
  2. 有更好的方法吗? (如果是的话,什么?)

任何帮助或建议将不胜感激!

I need a way of allowing a user to pick on option out of a list, I'm thinking of using a UIPickerView in a UIAlertView. However I was wondering if:

  1. It's possible to put a UIPickerView in a UIAlertView easily in iOS 5 (if so is it frowned upon by apple & will be app be rejected?)
  2. Is there a better way of doing this? (if so, what?)

Any help or advice would be really appreciated!

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

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

发布评论

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

评论(4

揪着可爱 2025-01-03 01:30:05

如果您要选择要放入屏幕上文本字段的值,只需让选择器查看文本字段的 inputView 即可。然后它会像键盘一样为您移动到位。

您可能还希望将工具栏添加为带有完成、下一步等按钮的 inputAccessoryView

使选择器视图成为输入视图非常简单。在您的 viewDidLoad 方法中,创建纠察队视图,正常设置其数据源和委托,然后将其分配给文本字段的输入视图属性:

myTextField.inputView = myPicker;

在您的选择器视图委托方法中,您可以在以下情况下使用所选值更新文本字段:选择器的选择已更改。在文本字段委托方法中,您可以确保纠察线在出现之前选择了正确的值(willBeginEditing?(猜测,不是在 mac ATM 上))。

附件视图可以只是一个带有单个完成项的 UIToolbar,该完成项告诉文本字段放弃第一响应者状态。再次设置它并在 viewDidLoad 中分配它。

If you are choosing a value to be put into a text field on the screen, just make your picker view the inputView of the text field. It will then animate into place for you just like the keyboard.

You may also wish to add a toolbar as an inputAccessoryView with done, next etc. buttons on it.

Making the picker view the input view is very simple. In your viewDidLoad method, create the picket view, setting its datasource and delegate as normal, then just assign it to the input view property of the text field:

myTextField.inputView = myPicker;

In your picker view delegate methods, you can update the text field with the selected value when the picker's selection is changed. In your text field delegate methods, you can make sure the picket has the right value selected before it appears (willBeginEditing? (guess, not at the mac ATM)).

The accessory view can just be a UIToolbar with a single done item that tells the text field to resign first responder status. Again, set this up and assign it in viewDidLoad.

孤独患者 2025-01-03 01:30:05

当然可以将 UIPickerView 添加为 UIAlertView 的子视图,我怀疑 Apple 会因此而拒绝您的应用程序,但我认为这会导致 UI 很差。为什么不直接创建一个新的 UIViewController 子类来包含 UIPickerView 并以模态方式呈现它?这是一种更常见的交互模式。

It's certainly possible to add a UIPickerView as a subview of a UIAlertView, and I doubt Apple would reject your app because of it, but I think it would make for a poor UI. Why not just create a new UIViewController subclass to contain the UIPickerView and present it modally? That's a much more common interaction pattern.

极致的悲 2025-01-03 01:30:05

如果您有 2-3 个选择,请将几个按钮放入 UIAlertView 中的 otherButtonTitles: 之后。如果你有更多的选择,你肯定需要构建新的视图控制器。甚至不要尝试将选择器视图添加到 UIAlertView 中。

If you have 2-3 choices put several buttons into UIAlertView after otherButtonTitles:. If you have more choices, definitely you need to build new view controller. Don't even try to add picker view into UIAlertView.

时光与爱终年不遇 2025-01-03 01:30:05

1) 我相信你可以在任何 iOS SDK 版本中轻松地做到这一点。由于 UIAlertViews 基本上是 UIViews 的子类,因此您可以简单地使用 addSubview:

2) 这取决于选项列表的上下文。对于生日、日期或时间等选择,Apple 使用单独的 UIViewController 以及 UITableView(一行)和 UIPickerView。如果以上三种都不是,苹果通常会使用 UITableView 来在用户的选择旁边打勾。

不管怎样,我认为每个人似乎都同意你应该打开带有选项列表的第二页。

1) You can easily do this in any of the iOS SDK versions, I believe. Since UIAlertViews are basically subclassed UIViews, you can simply use addSubview:

2) This depends the context of the options list. For choices like birthdays or date or time, Apple uses a separate UIViewController with a UITableView (one row) and a UIPickerView. If it's none of the three above, Apple generally seems to use a UITableView which puts a checkmark next to the person's choice.

Either way, I think everyone seems to agree that you should bring up a second page with the list of options.

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