加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – dismissModalViewControllerAnimated产生黑色背景

发布时间:2020-12-14 17:21:50 所属栏目:百科 来源:网络整理
导读:我的应用程序是创建csv文件并通过邮件发送它.但是当我丢弃邮件时,我会变黑屏幕.之前的视图没有出现,并且被黑屏覆盖.我在堆栈溢出中查看了各种问题和答案.但似乎没有任何效果. - (IBAction)openMail:(id)sender{ [self getdata]; if ([MFMailComposeViewContr
我的应用程序是创建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,Amountn" ;

        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];

}

解决方法

presentModalViewController:animated:和dismissModalViewControllerAnimated:从iOS6开始不推荐使用,就像旁注一样!
您要定位哪个iOS版本,这是您正在处理的iPhone或iPad应用程序?

除此之外,我注意到以下内容:

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

在呈现视图控制器后,您将设置modalPresentationStyle!移动行mailer.modalPresentationStyle = UIModalPresentationPageSheet;在presentModalViewController行之前.也许这就是问题所在!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读