我一直在寻找,我可能只是跳过它,但这就是我需要的。我有一个包含电子邮件地址列表的表格视图,我希望用户能够选择其中一个并让邮件编辑器视图弹出选择作为收件人的电子邮件地址。我找不到。
答案 0 :(得分:1)
那可能会这样做:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Get data from the datasource (supposing a one dimensional list)
NSString *theRecipent=[[self dataSource] objectAtIndex:[indexPath row]]
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self;
[mailCont setSubject:@"The Subject"];
[mailCont setToRecipients:[NSArray arrayWithObject:theRecipent]];
[mailCont setMessageBody:@"I should elaborate more my questions :P" isHTML:NO];
[self presentModalViewController:mailCont animated:YES];
[mailCont release];
}
}
// The delegate method
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
在didSelectRowAtIndexPath
内,您必须使用MFMailComposeViewController
课程发送电子邮件(检查您是否可以发送电子邮件总是好的)并发送电子邮件。
部分代码来自此answer。