我已经设置了一个 navController,它会在点击按钮后出现。但是,如果我点击按钮,我会收到以下错误:“Warning: Attempt to present <UINavigationController>: 0xab5d9d0 on <MyApp: 0xadaa320> whose view is not in the window hierarchy!
”
有人知道怎么解决吗?我还在 Stackoverflow 上尝试了一些东西,但这不是我的解决方案。
这是我打开导航 Controller 的代码:
我不知道是否有人知道这个照片库,但如果你不知道,here是项目。
我的代码(MyApp.m):
#import MyApp.h
...
//some stuff
- (void)launchGalleryView
{
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
// Set browser options.
browser.wantsFullScreenLayout = YES;
browser.displayActionButton = NO;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];
NSMutableArray *photos = [[NSMutableArray alloc] init];
MWPhoto *photo;
photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"callculator" ofType:@"jpg"]];
photo.caption = @"The calculator is soo beateful...";
[photos addObject:photo];
self.photos = photos;
[self presentModalViewController:navController animated:NO];
}
提前致谢。
编辑:
它在资源和编译源中,但在资源中您可以看到它是红色的( Storyboard)。可能是这个原因造成的?
第二个 Controller .h:
@class MyApp;
@interface Second : UIViewController <MWPhotoBrowserDelegate> {
}
@property (nonatomic, retain) MyApp* vC;
@end
第二 Controller .m:
#import "Second.h"
#import "MyApp.h"
@interface Second ()
@end
@implementation Second
@synthesize vC;
//some stuff in here
//the action
- (IBAction)dothis:(id)sender {
NSLog(@"launch the navcontroller");
[self.vC launchGalleryView];
}
MyApp.h:
#import "Second.h"
@interface myApp : UIViewController <MWPhotoBrowserDelegate> {
}
-(void)launchGalleryView;
NSArray *_photos;
新编辑:
我发现我必须在 viewDidAppear 中调用方法“launchGalleryView”,但是我如何在每次加载 View 时不调用 navcontroller 的情况下执行此操作?有谁知道如何做到这一点?
最佳答案
我检查了你的项目..无法解决正确的问题..
但我尝试了一个 hack 并且成功了..
将这一行替换为
[self presentModalViewController:navController animated:YES];
这个
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:navController animated:YES];
关于iphone - 谁的 View 不在窗口层次结构问题中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13888062/