Luk*_*uke 6 iphone uiviewcontroller ios uidocumentinteraction
我的主菜单上有一个常规的UIButton,它当前启动了一个UIViewController; 相应的.m文件的内容如下:
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
documentPath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:documentPath];
document = [UIDocumentInteractionController interactionControllerWithURL: targetURL];
document.delegate = self;
[document retain];
return self;
}
-(UIViewController *)documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
return self;
}
-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[document autorelease];
}
-(void)viewDidLoad
{
[super viewDidLoad];
[document presentPreviewAnimated: YES]; // ** CRASH **
}
-(void)viewDidUnload
{
[super viewDidUnload];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)dealloc
{
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
我的pdf文件按预期加载,但是当我点击"完成"按钮时,文档关闭,我只是盯着我的空白UIViewController - 可以说是预期的.但是,如果我点击导航"后退"按钮,那么应用程序会在我的viewDidLoad方法中发生错误的访问错误而崩溃,其中找到了对presentPreviewAnimated的调用.
如果有人可以请一看,我将非常感激.
(顺便说一句,创建这个视图控制器时没有NIB文件.是的,这本身就错了)
我想知道问题是否在于您在视图创建期间执行此操作。这样,当用户关闭文档预览时,它会返回到未完全形成的 UIView。那么也许首先构建并加载视图,然后从 viewDidAppear 执行 UIDocument ?
| 归档时间: |
|
| 查看次数: |
5981 次 |
| 最近记录: |