编辑:错误与 PDF 生成期间使用的数据结构有关。一旦获得支持 iOS7 的 OSX 副本,我就可以对其进行调试。感谢大家的帮助!
在工作中,我的 Mac 专用于处理 iOS 6 应用程序。到目前为止,还无法更新到较新版本的 OSX,因此我的 XCode 版本无法升级以自然支持 iOS7。长话短说,我无法调试 iOS7 应用程序,所以我不确定应用程序崩溃的原因。
我有一个 UIActionSheet。我曾经将一个与那些完成 block 一起使用,但我试图进行调试,所以我将所有内容都去掉了,只剩下基本的准系统,但当我点击按钮时它仍然崩溃。
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send by Email", @"Send To...", @"Open In...", nil ];
[actionSheet showFromBarButtonItem:sender animated:YES];
这只是 PDF 生成方法的末尾。
有什么想法吗?我整个下午都在研究这个,但我还没有找到它会像这样停止工作的任何原因。我确实尝试将操作表作为数据存储在 View Controller 中,以便保留引用,但无济于事。
我正在使用 ARC。
编辑: 我尝试了一个 UIAlertView,结果相同。也许是 PDF 上下文以某种方式破坏了一切?
感谢大家的帮助。
编辑: 解决这个问题的重大突破:当注释掉我的操作表/模式对话框/警报 View 之前的 PDF 生成代码时,它会毫无怨言地打开。所以这是某种混合问题,我将在此处发布我的大部分方法,以便每个人都能看到发生了什么:
-(void)shareTapped:(id)sender
{
if (actionSheet.isVisible)
return;
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No mail setup" message:@"You must setup your email in the main settings app before you can share." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
{
// should only get run once due to UI
Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:@"ipc"];
[[PPCalculation sharedInstance] openCalculation:path];
}
[[PPCalculation sharedInstance] calculate];
// let's generate the PDF here!
NSMutableData* pdfData = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );
UIGraphicsBeginPDFPage();
// 200 lines of drawing commands here
UIGraphicsEndPDFContext();
// save to file
NSString* path;
for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
{
// should only get run once due to UI
Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString* filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:@"pdf"];
[[NSFileManager defaultManager] createFileAtPath:path
contents:pdfData
attributes:nil];
}
// ActionSheet, modal dialog, composer dialog, alert view, all of them crash when I try to put them here
UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send By Email", nil];
[sheet showFromBarButtonItem:sender animated:YES];
}
再次感谢各位。
编辑:从我的调查和逐行评论并通过 TestFlight 将它们发送到设备来看,似乎是内部数据结构无法正常工作,这很奇怪,因为该应用程序的其余部分工作正常。我可能会得到 Mountain Lion 或其他东西的副本,这样我就可以正确地调试它。
最佳答案
尝试下面的代码...可能会对您有所帮助...
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send by Email", @"Send To...", @"Open In...", nil];
//actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.tag = ((UIButton*)sender).tag;
[actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];
关于ios - UIActionSheet 在 iOS6 中工作正常,但在 iOS7 中崩溃——数据结构有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20347719/