gpt4 book ai didi

iphone - dismissModalViewControllerAnimated 产生黑色背景

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:01 25 4
gpt4 key购买 nike

我的应用程序是创建 csv 文件并通过邮件发送。但是当我丢弃邮件时,我会黑屏。之前的 View 没有出现,并被黑屏覆盖。在stack overflow中查看了各种问答。但似乎没有任何效果。

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

您在呈现 View Controller 后设置 modalPresentationStyle!将行 mailer.modalPresentationStyle = UIModalPresentationPageSheet; 移到 presentModalViewController 行之前。也许这就是问题所在!

关于iphone - dismissModalViewControllerAnimated 产生黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12858198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com