2013-05-11 52 views
0

我使用Github上的JTRevealSidebar。我有問題,當我點擊左側邊欄(反饋)中的一個單元格,我想打開MailComposer。 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:@"[email protected]",nil]]; 

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

     } 
    } 

} 

回答

1

首先你應該關閉你所在的視圖控制器。這是因爲側邊欄本身就是一個視圖控制器。然後展示mailController,以便它顯示在中央視圖控制器中。

代碼更改:

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

使用這個代替:

[self dismissViewControllerAnimated:YES completion:nil]; 
+0

我看到這個錯誤... 錯誤: 'SidebarViewController' 不可見的@interface聲明選擇 'dismissModalViewController' [self dismissModalViewController]; 我用這個解決方案測試,但我有同樣的問題: [self dismissModalViewControllerAnimated:NO]; – NoBody 2013-05-11 14:59:16

+0

編輯了答案 – lakesh 2013-05-11 18:43:35