MailComposer在补充工具栏中打开

时间:2013-05-11 13:50:03

标签: ios objective-c sidebar

我使用Github的JTRevealSidebar。当我点击左侧边栏中的单元格(反馈)时,我有问题,我想打开MailComposer。 MailComposer已打开,但仅在左侧边栏内。有人能帮助我吗?

enter code here

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    /*if (self.sidebarDelegate) {
        NSObject *object = [NSString stringWithFormat:@"ViewController%d", indexPath.row];
        [self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
    }*/

    if(indexPath.section == 0){
        if(indexPath.row == 1){ // Feedback{
            MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
            mailController.mailComposeDelegate = self;

            [mailController setSubject:@"Feedback für testapp"];
            // Fill out the email body tex
            NSString *emailBody = [NSString stringWithFormat:@"\n\n\n\nApp: %@ \n App-Version: %@ \nModel: %@ \n Version: %@",
                                   @"TestApp",
                                   [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"],
                                   [UIDevice currentDevice].model,
                                   [UIDevice currentDevice].systemVersion];
            [mailController setMessageBody:emailBody isHTML:NO];
            [mailController setToRecipients:[NSArray arrayWithObjects:@"support@testapp.com",nil]];

            dispatch_async(dispatch_get_main_queue(), ^{
                // whatever code you want to run on the main thread
                [self presentModalViewController:mailController animated:YES];
            });

        }
    }

}

1 个答案:

答案 0 :(得分:1)

首先你要解雇你所在的视图控制器。这是因为侧边栏本身就是一个视图控制器。然后呈现mailController,以便它显示在中心viewcontroller中。

代码更改:

dispatch_async(dispatch_get_main_queue(), ^{
 [self dismissModalViewController];
 [self presentModalViewController:mailController animated:YES];
});

请改用:

[self dismissViewControllerAnimated:YES completion:nil];