iphone – dismissModalViewControllerAnimated产生黑色背景

iphone – dismissModalViewControllerAnimated产生黑色背景,第1张

概述我的应用程序是创建csv文件并通过邮件发送它.但是当我丢弃邮件时,我会变黑屏幕.之前的视图没有出现,并且被黑屏覆盖.我在堆栈溢出中查看了各种问题和答案.但似乎没有任何效果. - (IBAction)openMail:(id)sender{ [self getdata]; if ([MFMailComposeViewController canSendMail]) { 我的应用程序是创建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];}
解决方法 presentModalVIEwController:animated:和dismissModalVIEwControllerAnimated:从iOS6开始不推荐使用,就像旁注一样!
您要定位哪个iOS版本,这是您正在处理的iPhone或iPad应用程序?

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

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

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

总结

以上是内存溢出为你收集整理的iphone – dismissModalViewControllerAnimated产生黑色背景全部内容,希望文章能够帮你解决iphone – dismissModalViewControllerAnimated产生黑色背景所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1004701.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存