iphone - 如何从 UITextfield 获取值并将其发送到电子邮件?

标签 iphone ios xcode uitextfield

我创建了一个应用程序,其中包含表单并且必须在适当的文本字段中填写..现在我需要在文本字段中获取所有数据并将其发送到电子邮件中。这是我编写电子邮件的代码

- (IBAction)compose:(id)sender 
{
if (text1.text=@"" && text2.text=@"" && text3.text=@"" && text4.text=@"" && text5.text=@"") {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                                                    message:@"Please enter all the field details" 
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles: nil];
}
                                                                             else{


if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

    mailer.mailComposeDelegate = self;

    [mailer setSubject:[NSString stringWithFormat:@"Appointment From Mr/Mrs. %@",text1.text]];

    NSArray *toRecipients = [NSArray arrayWithObjects:@"xxx@xxxx.com", nil];
    [mailer setToRecipients:toRecipients];



    NSString *emailBody =[NSString stringWithFormat:@"Name =%@\nDate= %@\nPreferred Time Slot= %@\nE-Mail=%@\nSpecific Requests=",text1.text,text2.text,text3.text,text4.text,text5.text]; 
    [mailer setMessageBody:emailBody isHTML:NO];


    [self presentModalViewController:mailer animated:YES];

    [mailer release];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                                                    message:@"Your device doesn't support the composer sheet" 
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
}
}

如果所有文本字段都为空,则它必须弹出警报。但是我收到错误消息?...请指导我...

最佳答案

如果您想知道如何从文本字段中获取文本并发送它,您将需要使用 textfield.text

NSString *emailBody = textField.text;
[mailer setMessageBody:emailBody isHTML:NO];

关于iphone - 如何从 UITextfield 获取值并将其发送到电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11205750/

相关文章:

css - 移动设备上的 Wordpress 下拉菜单没有响应/工作

ios - 应用程序在后台时的 Firebase 监听器

ios - 跨关系解析 PFQuery

objective-c - 如何从 NSString 中删除/替换/显示 unicode 字符

ios - 纵向和横向模式下的不同布局

swift - 如何在 Xcode (swift) 中使文本自动滚动到右侧?

ios - iPad 在 iOS 6 上使用 iPhone Storyboard而不是 iPad Storyboard

ios - 在 UIWebView 上无法选择照片?

ios - 当方法重新运行时,在方法中循环 dispatch_after 会导致许多同时调度

ios - iOS 是否支持 SVG Tiny?