dismissModalViewControllerAnimated создает черный фон

Мое приложение - создать CSV-файл и отправить его по почте. Но когда я сбрасываю почту, я получаю черный экран. Предыдущее представление не отображается и закрывается черным экраном. Я просмотрел различные вопросы и ответы в переполнении стека. Но, похоже, ничего не работает.

- (IBAction)openMail:(id)sender
{
    [self getdata];

    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
        [mailer setSubject:@"BMNET- Travel Log"];




        NSString *CSVstring=@"Name, StartingDateNTime, EndingDateNTime, TravelType, DistanceTravelled, Amount\n" ;

        NSString *CSVPath,*record;;

        NSString  *temporayCSV= @"" ;

           for (int i=0; i<[getAmount count]; i++) {    

               record = [NSString stringWithFormat:@"%@, %@, %@, %@, %@, %@", [getName objectAtIndex:i],   [getStartDate objectAtIndex:i],   [getEndDate objectAtIndex:i],[getType objectAtIndex:i],[getDistance objectAtIndex:i],[getAmount objectAtIndex:i]];



                      NSLog(@"%d",i);

                      temporayCSV = [NSString stringWithFormat:@"%d  %@  \n ",(i+1),record];

                      CSVstring = [CSVstring stringByAppendingFormat:temporayCSV];       
                      NSLog(@"%@",CSVstring);

          }

        NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                                             NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [paths objectAtIndex:0]; 

        NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
        [mailer setToRecipients:toRecipients];
        CSVPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.csv", @"CSV_FormatedTable"]];
        NSFileManager *fileManager;
        //add our file to the path
        [fileManager createFileAtPath:CSVPath contents:[CSVstring dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
        NSData *rolesCSVData =[NSData dataWithContentsOfFile:CSVPath];
        NSLog(@"The data is %@",CSVstring);

        //create my data to append
        NSFileHandle *handle;
        handle = [NSFileHandle fileHandleForWritingAtPath: CSVPath ]; 
        //say to handle where's the file fo write
        [handle truncateFileAtOffset:[handle seekToEndOfFile]]; 
        //position handle cursor to the end of file
        [handle writeData:[data dataUsingEncoding:NSUTF8StringEncoding]];   
        //write data to with the right encoding






        [mailer addAttachmentData:rolesCSVData mimeType:@"text/csv" fileName:@"Log"];
        NSString *emailBody = @"Attachment of Log";
        [mailer setMessageBody:emailBody isHTML:NO];
        [self presentModalViewController:mailer animated:YES];
        mailer.modalPresentationStyle = UIModalPresentationPageSheet;

    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {

        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");

            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");

            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");

            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");

            break;
        default:
            NSLog(@"Mail not sent.");

            break;
    }
    // Remove the mail view

    [self dismissModalViewControllerAnimated:YES];

}

1 ответ

Решение

presentModalViewController:animated: а также dismissModalViewControllerAnimated: устарели, начиная с iOS6, просто как примечание! на какие версии iOS вы нацеливаетесь и над этим приложением iPhone или iPad вы работаете?

кроме того, я заметил следующее:

[self presentModalViewController:mailer animated:YES];
mailer.modalPresentationStyle = UIModalPresentationPageSheet;

Вы устанавливаете modalPresentationStyle после того, как представили контроллер представления! переместить линию mailer.modalPresentationStyle = UIModalPresentationPageSheet; перед строкой presentModalViewController. Может быть, это проблема!

Другие вопросы по тегам