Search code examples
iosobjective-csidebar

MailComposer open in the Sidebar


i use the JTRevealSidebar from Github. I have problem when i clicked on a cell in the left Sidebar(Feedback) i want to open the MailComposer. The MailComposer is open but only inside the left Sidebar. Can anybody help me?

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:@"[email protected]",nil]];

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

        }
    }

}

Solution

  • First you should dismiss the viewcontroller you are in. This is because the sidebar is an viewcontroller on its own. Then present the mailController, so that it shows in the center viewcontroller.

    Code Change:

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

    Use this instead:

    [self dismissViewControllerAnimated:YES completion:nil];