我用来使用以下代码从splitviewcontroller的RootViewcontroller中显示一个viewcontroller。在iOS 5.1纵向模式下它不会显示任何内容。当横向显示Rootviewcontroller内的控制器时。它适用于iOS 5.0。
-(void)displayFileInReader:(NSURL *)fileURL {
SPDocumentReader *objiPadDocumentReader = [[SPDocumentReader alloc] init];
objiPadDocumentReader.readerType = ReaderTypeLocalCachedDocument;
objiPadDocumentReader.url = fileURL;
UINavigationController *objNavigationController = [[UINavigationController alloc] initWithRootViewController:objiPadDocumentReader];
objNavigationController.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:objNavigationController animated:YES];
[objNavigationController release];
objNavigationController = nil;
[objiPadDocumentReader release];
objiPadDocumentReader = nil;
}
我使用 self.splitviewcontroller 并使用 detailviewcontroller实例而不是self。
但是在这种情况下,当我们点击o detailview控制器来解除/删除rootviewcontroller它会导致崩溃时说“没有视图窗口”。
有时在iOS 5.1中,RootView显示方向错误。
提前致谢
答案 0 :(得分:5)
最后我找到了解决方案,
我认为问题可能是由于分割视图在我们尝试在其上呈现视图控制器时无法关闭根视图控制器。 我像这样改变了上面的功能
-(void)displayFileInReader:(NSURL *)fileURL
{
SPDocumentReader *objiPadDocumentReader = [[SPDocumentReader alloc] init];
objiPadDocumentReader.readerType = ReaderTypeLocalCachedDocument;
objiPadDocumentReader.url = fileURL;
UINavigationController *objNavigationController = [[UINavigationController alloc] initWithRootViewController:objiPadDocumentReader];
objNavigationController.navigationBar.barStyle = UIBarStyleBlack;
//to dismiss the splitview popover -to solve iOS5.1 splitview issue.
[self.delegate dismissSplitViewPopOverController];
[self presentModalViewController:objNavigationController animated:YES];
[objNavigationController release];
objNavigationController = nil;
[objiPadDocumentReader release];
objiPadDocumentReader = nil;
}
在这里,我粘贴了分割视图委托,允许我找到分割视图弹出窗口。
#pragma mark - UISplitView delegate
// Called when rotating to a portrait orientation.
- (void)splitViewController: (UISplitViewController*)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem*)barButtonItem
forPopoverController: (UIPopoverController*)pc {
barButtonItem.title = SPLocaleString(@"[Navigator]");
self.navigationItem.leftBarButtonItem = barButtonItem;
splitPopoverController = pc;
[splitPopoverController retain];
}
// Called when the view is shown again in the split view, invalidating the button and popover controller.
- (void)splitViewController: (UISplitViewController*)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
self.navigationItem.leftBarButtonItem = nil;
[splitPopoverController release];
splitPopoverController = nil;
}
-(void)splitViewController:(UISplitViewController *)svc
popoverController:(UIPopoverController *)pc
willPresentViewController:(UIViewController *)aViewController
{
if (splitPopoverController)
{
[splitPopoverController release];
splitPopoverController = nil;
}
splitPopoverController = pc;
[splitPopoverController retain];
}
- (void)dismissSplitViewPopOverController {
// If a popover controller is visible, hide it
if (splitPopoverController) {
[splitPopoverController dismissPopoverAnimated:NO];
[splitPopoverController release];
splitPopoverController = nil;
}
}
谢天谢地,
答案 1 :(得分:1)
由于solution by NaveenShan,我能够在5.1中解决此问题,但我唯一需要的就是在致电[popoverController dismissPopoverAnimated:NO];
之前致电presentModalViewController
。