我创建了一个应用程序,其中包含表单并且必须填写适当的文本字段。现在我需要在文本字段中获取所有数据并将其发送到电子邮件中。这是我撰写电子邮件的代码
- (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];
}
}
}
如果所有文本字段为空,则必须弹出警报。但我遇到错误?...请指导我..