【发布时间】:2017-01-06 21:31:48
【问题描述】:
有一些意想不到的事情我无法解决。我有一个alertController 和textfields。我尝试获取其中一个的字符串值。当字符串长度小于 11 个字符时,一切正常。高于此阈值,字符串为null。
谁能告诉我发生了什么?
以防万一,我把我的代码放在下面:
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Name";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSArray *textfields = alertController.textFields;
UITextField *nameTextfield = textfields[0];
self.textFieldString = nameTextfield.text;
NSLog(@"self.textFieldString is: %@", self.textFieldString); // -> this returns a null value when the string length is > 11
}]];
谢谢!
【问题讨论】:
-
你有解决方案了吗?
-
还没有,但我还没有时间去挖掘它(生病......)。我会让你知道。谢谢提问!
-
显然问题与“弱”属性分配有关,但我不明白为什么它使用较短的字符串长度。一个谜。但是感谢您的帮助!
标签: objective-c string uitextfield uialertcontroller