【发布时间】:2014-07-30 18:02:32
【问题描述】:
我有一个适用于 3 个不同办公室的应用程序,我希望能够选择将生成的整理数据通过电子邮件发送到哪个办公室。我想为每个办公室使用不同的按钮,该按钮将自动填充电子邮件收件人,然后最后的按钮将整理所有信息并将其全部附加到电子邮件中。有没有办法做到这一点?我已经弄清楚了发送按钮,它填充了我无法解决的收件人。
这是我拥有的电子邮件部分,但由 1 个电子邮件地址填充,而不是取决于此刻按下的按钮。
- (IBAction)checkData:(id)sender
{
unsigned int x,a = 0;
NSMutableString *emailmessage;
emailmessage = [NSMutableString stringWithFormat: @""];
for (x=0; x<9; x++)
{
switch (x) {
case 0:
if (nameTextField.text == nil) {
[emailmessage appendString:@"Name, "];
a=1;
}
break;
case 1:
if (emailTextField.text == nil)
{
[emailmessage appendString:@"Email Address, "];
a=1;
}
break;
case 2:
if (dateLabel.text == nil)
{
[emailmessage appendString:@"Date and Time of Near Miss, "];
a=1;
}
break;
case 3:
if (locationTextField.text == nil)
{
[emailmessage appendString:@"Location of Near Miss, "];
a=1;
}
break;
case 4:
if (locLabel.text == nil)
{
[emailmessage appendString:@"GPS Location, "];
a=1;
}
break;
case 5:
if (observersTextField.text == nil)
{
[emailmessage appendString:@"Observers Team, "];
a=1;
}
break;
case 6:
if (affectedTextField.text == nil)
{
[emailmessage appendString:@"Affected Team, "];
a=1;
}
break;
case 7:
if (catLabel.text == nil)
{
[emailmessage appendString:@"Rating Classification, "];
a=1;
}
break;
case 8:
if (onOffLabel.text == nil)
{
[emailmessage appendString:@"Third Party?, "];
a=1;
}
break;
case 9:
if (mlabelcategory.text == nil)
{
[emailmessage appendString:@"Category, "];
a=1;
}
break;
case 10:
if (messageTextView.text == nil)
{
[emailmessage appendString:@"Observation Description, "];
a=1;
}
break;
case 11:
if (activityTextView.text == nil)
{
[emailmessage appendString:@"Type of Work Activity, "];
a=1;
}
break;
case 12:
if (imageView.image == nil)
{
[emailmessage appendString:@"Image, "];
a=1;
}
break;
default:
break;
}
}
{
name = nameTextField.text;
emailaddress = emailTextField.text;
date = dateLabel.text;
location = locationTypeBtn.text;
observers = originatorTypeBtn.text;
affected = destinationTypeBtn.text;
rating = catLabel.text;
thirdparty = onOffLabel.text;
category = categoryTypeBtn.text;
message = messageTextView.text;
activity = activityTextView.text;
gps = locLabel.text;
NSMutableString *nearmissreport;
nearmissreport = [NSMutableString stringWithFormat: @"<br><br> <b>Name:</b> %@ <br> <b>Email Address:</b> %@ <br><br> <b>Date & Time of Near Miss:</b> %@ <br><br> <b>Location of Near Miss:</b> %@ <br> <b>GPS Location:</b> %@ <br><br> <b>Observers Team:</b> %@ <br> <b>Affected Team:</b> %@ <br><br> <b>Rating Classification:</b> %@ <br><br> %@ <br><br> <b>Category:</b> %@ <br><b>Observation Description:</b> %@ <br><br> <b>Type of Work Activity:</b> %@ <br><br><b>Image:</b><br>", name, emailaddress, date, location, gps, observers, affected, rating, thirdparty, category, message, activity];
NSLog(@"Near Miss Report: %@", nearmissreport);
NSMutableString *testoMail;
testoMail = [NSMutableString stringWithFormat: nearmissreport];
NSLog(@"%@", testoMail);
//MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject: rating];
// Set up the recipients.
NSArray *toRecipients = [NSArray arrayWithObjects:@"example@example.com",nil];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com",@"third@example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObjects:@"four@example.com",nil];
[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email.
NSData *imageData = UIImagePNGRepresentation([imageView image]);
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"NearMiss"];
// Fill out the email body text.
//NSMutableString *emailBody;
testoMail = [NSMutableString stringWithFormat: @"%@", testoMail];
[picker setMessageBody:testoMail isHTML:YES]; //HTML!!!!!!
// Present the mail composition interface.
[self presentViewController:picker animated:YES completion:nil];
}
}
// The mail compose view controller delegate method
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES];
}
【问题讨论】:
-
使用
button.tag来识别按下了哪个按钮。 :) -
嗨@AbhishekBedi,我想你不知道有什么好的例子可以告诉我如何使用button.tag?
-
我看不到 button.tag 如何填充收件人电子邮件?