我有一个实用程序。我已经在另一面实现了这个代码,它调用一个反馈视图来发送电子邮件,就像这个教程一样。这可行,但是当我单击发送反馈 UIButton 时,我的应用程序立即崩溃*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController sendMail]: unrecognized selector sent to instance 0x89c1960'.
我检查了这些东西:
我已经正确声明了委托并为 MailComposer 实现了它。
我的方法 sendMail 连接到按钮的 TouchUp 事件。
我的方法名称同意:
- (IBAction)sendMail;
和
- (IBAction)sendMail
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mfViewController = [[MFMailComposeViewController alloc] init];
mfViewController.mailComposeDelegate = self;
[self presentModalViewController:mfViewController animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status:" message:@"Your phone is not currently configured to send mail." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
}
}
代码不会到达此方法,因为我在方法实现的顶部设置了一个断点,但没有被调用。ViewDidLoad 处的断点也没有被激活。
仔细查看此错误:
reason: '-[UIViewController sendMail]: unrecognized selector sent to instance
似乎它需要一个名为 sendMail 而不是方法的视图控制器。我读了这篇看起来非常相似的帖子,但我在 xib 身份下拉列表中没有看到任何其他视图控制器名称。我认为这是我的问题的一部分,但我不知道如何解决它。
也许我应该通过视图控制器展示 MFMailComposer?如果是这样,我不知道该怎么做。
任何建议,将不胜感激。