Access textfield of UIAlertController - swift ios8

十年热恋 提交于 2019-12-12 13:46:35

问题


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>>

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.


回答1:


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)


来源:https://stackoverflow.com/questions/25068620/access-textfield-of-uialertcontroller-swift-ios8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!