访问 UIAlertController 的文本字段 - swift ios8 [英] Access textfield of UIAlertController - swift ios8
本文介绍了访问 UIAlertController 的文本字段 - swift ios8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试访问 UIAlertView 的文本字段,我正在使用 textFields
属性,我从 textFields
属性获得以下输出:>
I'm trying to access the text field of a UIAlertView and I'm using the textFields
property and I get the following output from the textFields
property:
<_UIAlertControllerTextField: 0x7fe911f96790;
frame = (4 4; 231 16);
text = 'THIS IS THE TEXT THAT I JUST ENTERED';
clipsToBounds = YES; opaque = NO;
gestureRecognizers = <NSArray: 0x7fe914215cc0>;
layer = <CALayer: 0x7fe911f96c40>>
如您所见,文本确实显示了,但我需要单独显示文本.textFields.text
将不起作用,因为它已被弃用且不能在 Swift 中使用.
As you can see the text does show up, but I need the text separately. textFields.text
won't work because its deprecated and cannot be used in Swift.
推荐答案
textField 存储在 AnyObject 数组中.如果您想访问文本,您应该首先将其转换为 UITextField:
The textFields are stored in an Array of AnyObject. If you want to access text you should cast it as a UITextField first:
((alert.textFields[0] as UITextField).text)
这篇关于访问 UIAlertController 的文本字段 - swift ios8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文