简单的iOS从UIAlertView收集字符串

use*_*987 2 string iphone nsstring uialertview ios

我试图将数据发布到数据库,但问题是我似乎无法从用户获取在UIAlertView中输入的文本.我已经尝试了很多解决方案,例如子视图UITextField,但没有运气.这是我目前的简单配置.如果您需要更多信息,请与我们联系.

- (void)viewDidLoad
{
    [super viewDidLoad];

    //load site in webview
    NSURLRequest *siteRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com/"]
                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
                                 [webview loadRequest:siteRequest];


    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Please enter your email address." delegate:self cancelButtonTitle:@"Submit" otherButtonTitles:@"Skip", nil];
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *emailInput = [alertView textFieldAtIndex:0];
    [alertView show];

    emails=emailInput.text;

  //  NSLog(emails);


    phone=@"8675309";

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*bri 5

您需要获取有关UIAlertViewDelegate方法的电子邮件:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    UITextField *emailInput = [alertView textFieldAtIndex:0];
    NSLog(@"%@",emailInput.text);
}
Run Code Online (Sandbox Code Playgroud)