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