- (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产生黑色背景所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)