0

在过去的两天里,我只是试图在我的应用程序中启用电子邮件发送功能。希望这里的聪明人之一可以帮助我。presentModalViewController 对我不起作用(只是让应用程序崩溃而没有解释原因),所以我不得不添加 MFMailComposeViewController 的视图。这是我的尝试:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"test subject"];
    [controller setMessageBody:@"this is the message body" isHTML:NO];

    //  [self presentModalViewController:controller animated:YES]; //this crashes the app
//so I try this instead:        
    controller.view.frame = CGRectMake(0,0,480,320);
    [self.view addSubview:controller.view];
    [controller release];

添加到屏幕上的只是主题栏,带有取消和发送按钮。不显示任何文本字段(收件人:、抄送:、主题、正文)。为什么它们不是 MFMailComposeViewController 视图的一部分,我该如何显示它们?

4

5 回答 5

2

老实说,你应该使用presentModalViewController. 与其强行绕过 SDK,不如考虑调试崩溃。打开调试器,查看控制台中是否记录了任何异常。检查崩溃日志等...

此外,请确保它self是正确的委托和 UIViewController 子类。

于 2009-07-05T00:29:39.780 回答
2

我已经解决了这个问题:

试试这个:

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];

但是这个:

MFMailComposeViewController *mailComposeViewController = [MFMailComposeViewController new];
于 2011-11-07T08:13:51.070 回答
1

您应该尝试:

[[self navigationController] presentModalViewController...];

因为这是呈现它的正确方式。不幸的是,尝试手动添加其视图是完全不正确的,并且永远不会起作用。

于 2009-07-05T00:27:48.553 回答
1

好吧,我已经确定必须创建一个虚拟视图控制器,否则该死的东西不会滑入。

我创建了一个名为的Sys_Mail@interface Sys_Mail : UIViewController <MFMailComposeViewControllerDelegate>

然后我基本上创建了一个根视图视图控制器。我与纵向/横向搏斗了几个小时,但确定如果您将视图控制器附加到顶层视图(其中包含我的横向变换),那么它会作为横向窗口滑入。只有一个视觉故障,父窗口在新窗口滑入时移动了几秒钟,这是景观变换对父窗口做奇怪事情的副作用......

为了在滑动窗口上获得横向方向,您必须在您的Sys_Mail类中声明一个处理自动旋转消息的方法:

//=======================
//    shouldAutorotateToInterfaceOrientation
//=======================
//  see if this ever gets called for the view controller
-(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation 
{ 
  if (TRACE) printf ("shouldAutorotateToInterfaceOrientation\n");
  return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);  // or whatever orientation is needed
}

该变量gMasterView指的是我的顶级视图(具有景观变换并附加到窗口)。子视图似乎不起作用,视图控制器很糟糕,它们更像是设计模式垃圾。我想要完全控制我的观点,而不是一些微软 MFC 类型的杂物!

Sys_Mail* g_root_vc;

if (g_root_vc == nil) {
  //  create an empty view controller so we have something to work with
  g_root_vc = [[Sys_Mail alloc] init];
  g_root_vc.view = (UIView*) gMasterView; 
}

所以这

于 2009-08-16T00:01:36.833 回答
0

我有同样的崩溃,最后我可以通过向 [self navigationController] 发送 presentModalViewController 消息来修复它。

这是我的代码:

// Create the Mail composer view controller
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];

// Set the view controller delegate
controller.mailComposeDelegate = self;

// Set recipients, if you want
[controller setToRecipients:recipients];

// Set subject, if you want
[controller setSubject:@"The subject"];

// Set message body, if you want
[controller setMessageBody:@"The message body" isHTML:YES]; // isHTML -> YES/NO depending the message body

// Present the view controller 
[[self navigationController] presentModalViewController:controller animated:YES];

// Memory management
[controller release];

我希望这能有所帮助!

于 2010-08-06T19:36:12.803 回答