【问题标题】:UITableView for mail contacts [closed]邮件联系人的 UITableView [关闭]
【发布时间】:2012-02-22 11:10:02
【问题描述】:

我一直在寻找,我可能只是跳过了它,但这是我需要的。我有一个包含电子邮件地址列表的表格视图,我希望用户能够选择其中一个,并让邮件编辑器视图弹出并选择该电子邮件地址作为收件人。我找不到它。

【问题讨论】:

  • 您能具体说明您的问题吗?
  • 切赫MFMailComposerViewController
  • 我知道 mfmailcompiserviewcontroller,但我想做的是在 uitableview 上显示电子邮件地址,当用户点击 uitable 单元格时,它将是 mfmailcomposerviewcontroller 中的电子邮件地址
  • 像你现在一样,你如何去你的联系人应用程序,查看联系人,并有一个带有电子邮件地址的单元格。如果您点击该电子邮件地址,它将打开一个以该电子邮件地址作为收件人的作曲家视图
  • 其实我想通了,我可以使用一些自定义单元格

标签: iphone objective-c ios email uitableview


【解决方案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

【讨论】:

  • 最好这样做。类 mailClass = NSClassFromString(@"MFMailComposeViewController"); if (mailClass != nil) { if([MFMailComposeViewController canSendMail]) { } }
  • 这样做有什么好处?我是来学习东西的:D
  • 对不起,我弄错了。没有必要这样做,但最好检查 ([[MFMailComposeViewController alloc] init]) 是否返回 nil。如果设备中没有设置邮件账户,([[MFMailComposeViewController alloc] init]) 在某些设备上返回nil,App崩溃,我遇到了这种情况。
  • 这就是为什么人们在提出此类简单问题之前需要阅读的原因。现在我回想起以前的问题,我意识到了这一点
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-07
  • 1970-01-01
  • 1970-01-01
  • 2015-10-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多