应用程序试图在目标<uinavigationcontroller:0x2007af00 =“”> </uinavigationcontroller上显示一个nil模态视图控制器:>

时间:2012-09-24 04:37:06

标签: iphone objective-c ios ipad

我收到以下错误:

Application tried to present a nil modal view controller on target <UINavigationController: 0x2007af00>.

在以下代码中:

-(void) showAddressBookDialog
{
    [self presentMailComposeViewController:nil];
}


- (void)presentMailComposeViewController:(NSString *)recipient {
    // Create the compose email view controller
    MFMailComposeViewController *composeEmailViewController = [[MFMailComposeViewController alloc] init];
    [composeEmailViewController setMailComposeDelegate:self];
    [composeEmailViewController setSubject:@"Join me on X"];
    [composeEmailViewController setToRecipients:[NSArray arrayWithObjects:recipient, nil]];
    [composeEmailViewController setMessageBody:@"" isHTML:YES];
    [composeEmailViewController setModalPresentationStyle:UIModalPresentationFormSheet];
    [self dismissModalViewControllerAnimated:NO];
    self.inviteFriendsMailComposerVC_ = composeEmailViewController;
    //[self.navigationController presentModalViewController:composeEmailViewController animated:YES];
    [self.navigationController presentViewController:composeEmailViewController animated:YES completion:nil];
    [composeEmailViewController release];
}

知道为什么吗?

2 个答案:

答案 0 :(得分:2)

我想知道你为什么先解雇你的观点...从你的方法中删除这一行

[self dismissModalViewControllerAnimated:NO];

最好首先检查设备是否配置为发送电子邮件。见link

答案 1 :(得分:0)

navigationController是所有UIViewControllers的属性,它为您提供父导航视图控制器(如果存在)。听起来你从未将yourviewController添加到导航控制器的视图控制器堆栈中。