无法关闭 iPhone 中的电子邮件编辑器视图?
我是 iPhone 开发新手。我创建了一个基于选项卡栏的应用程序。首先,我希望显示电子邮件编辑器。我可以显示它,但取消和发送按钮不起作用,我不知道哪里出了问题。请帮助我。这是我的代码。
- (void)viewDidLoad
{
[super viewDidLoad];
[self displayComposerSheet];
}
-(void)displayComposerSheet
{
picker = [[MFMailComposeViewController alloc] init];
[[picker navigationBar] setTintColor:[UIColor blackColor]];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail])
{
[picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]];
[picker setSubject:@"Sample"];
}
[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
I am new to iphone development.I have created a tabbar based application . In the first i want the email composer to be displayed. I am able to display it but the cancel and send button are not working,I don't know where do i go wrong .Please help me out. Here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
[self displayComposerSheet];
}
-(void)displayComposerSheet
{
picker = [[MFMailComposeViewController alloc] init];
[[picker navigationBar] setTintColor:[UIColor blackColor]];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail])
{
[picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]];
[picker setSubject:@"Sample"];
}
[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在向邮件编辑器展示两次。
删除行:
并将下一行替换为:
You are presenting the mail composer twice.
Remove the line:
And replace the next line with:
如果您仅添加 mailcomposser 的子视图,则必须将其从 self.view 中删除,
在您的代码中,您要添加子视图并也显示,
如果您仅使用
[self.view addSubview:picker.view];
则尝试将其删除。
我仍然建议对
Present MFMailComposeViewController 使用
[self.navigationControllerpresentModalViewController:pickeranimated:YES];
,并使用
[selfdismissModalViewControllerAnimated:YES];
关闭它。If you are adding only subview of mailcomposser you have to remove it from self.view,
In your code you are adding subview and present also,
If you are use only use
[self.view addSubview:picker.view];
thanTry with to remove it.
I'm still suggest to use
[self.navigationController presentModalViewController:picker animated:YES];
for Present MFMailComposeViewController ,and use
[self dismissModalViewControllerAnimated:YES];
to dismiss it.使用此代码:
Use this code:
设置 MFMailComposeViewController 的委托
并使用此委托方法
Set Delegate of MFMailComposeViewController
And Use this Delegate Method