iOS / UIAlertView 中的 UITextField
当用户按下我的“导入”按钮时,他们必须能够输入 URL,然后可以“确定”或“取消”。
我该怎么做?
显然我可以创建一个包含一个文本字段和 2 个按钮的新视图。但这似乎是过度编码。
我发现的一个解决方案涉及将 UITextField '黑客'到 UIAlertView 中: http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html
这看起来真的很难看。这显然是一个黑客行为。
任何人都可以提供更好的解决方案(甚至是同一解决方案路径的更好实现)吗?
When the user presses my 'import' button, they must be able to type in a URL, which they can then 'ok' or 'cancel'.
How do I do this?
Obviously I could create a new view containing a text field and 2 buttons. But this seems like over coding.
One solution I found involves ' hacking ' a UITextField into a UIAlertView: http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html
(EDIT: Better -- http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html#post10643 )
This looks really ugly. It is clearly a hack.
Can anyone provide a better solution (or even a better implementation of the same solution path)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,经过大量挖掘后,结果如下。
首先,将“UITextField UIAlertView”放入 SO 的搜索中会返回数十个命中。
事实证明有一种方法可以做到这一点, 需要将 UITextField 添加到 UIAlertView 的新方法,但它是私有 API :|
几乎所有其他解决方案都涉及破解 UIAlertView,这很丑陋:
http:// junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html
http://iphone-dev- Tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html
https://github.com/josecastillo/EGOTextFieldAlertView/
如何移动 UIAlertView 中的按钮以为插入的 UITextField 腾出空间?
^ MrGando 的回答很简洁
http://iphonedevelopment.blogspot.com/2009/02/ Alert-view-with-prompt.html
是
我发现的唯一正确的解决方案(即从 UIView 从头开始编码) 这里: https://github.com/TomSwift/TSAlertView
这就是所需要的:
和急!
OK After a ton of digging, here is the result.
Firstly, putting in 'UITextField UIAlertView' into SO's search returns dozens of hits.
It turns out there is a method for doing this, Need new way to add a UITextField to a UIAlertView but it is private API :|
Pretty much every other solution involves hacking a UIAlertView, which is ugly:
http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html
http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html
https://github.com/josecastillo/EGOTextFieldAlertView/
How to move the buttons in a UIAlertView to make room for an inserted UITextField?
^ MrGando's answer is neat
http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
Getting text from UIAlertView
The only proper solution I found (ie coding from scratch from a UIView) is here: https://github.com/TomSwift/TSAlertView
This is all it takes:
and Presto!
查看:https://github.com/enormego/EGOTextFieldAlertView
Check out: https://github.com/enormego/EGOTextFieldAlertView
我在博客中创建了一篇主题为“如何从 XIB 将 UITextField 添加到 UIAlertView”的帖子。使用 XIB 进行添加比纯粹编码更容易。您可以在自定义小视图中添加任何内容,然后使用 1 行代码将小视图添加到 AlertView 中。请参考以下链接。
http://creiapp.blogspot.com/2011 /08/how-to-add-uitextfield-to-uialertview.html
I have created a post in my blog on the topic "How to add UITextField to UIAlertView from XIB". Using XIB to add is easier than pure coding. You can add whatever in a customized small view, then add the small view into the AlertView using 1 line code. Please refer to the following link.
http://creiapp.blogspot.com/2011/08/how-to-add-uitextfield-to-uialertview.html