如何解决使用obj-c
如何将文本字段放入UIAlertView?以及如何获取用户刚刚在文本字段中输入的字符串的值? 都带有Objective-C
非常感谢。
解决方法
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated{
[self alert];
}
- (void) alert {
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Name"
message: @"Input your new username"
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"username";
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSArray * textfields = alertController.textFields;
UITextField * usernamefield = textfields[0];
NSLog(@"%@",usernamefield.text);
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
@end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。