我已经设置了一个navController,它在点击按钮后出现。但是,如果我点击按钮,我会收到错误:“Warning: Attempt to present <UINavigationController>: 0xab5d9d0 on <MyApp: 0xadaa320> whose view is not in the window hierarchy!
”
有谁知道如何解决这个问题?我也尝试过Stackoverflow,但这不是我的解决方案。
这是我打开navigationcontroller的代码:
我不知道是否有人知道这个照相馆,但如果你不知道,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];
}
提前致谢。
修改
它位于recources和编译源中,但在资源中你可以看到它是红色的(故事板)。也许是由此造成的?
第二个控制器.h:
@class MyApp;
@interface Second : UIViewController <MWPhotoBrowserDelegate> {
}
@property (nonatomic, retain) MyApp* vC;
@end
Secnond控制器.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”但是如何在每次加载视图时都不调用navcontroller来执行此操作?有谁知道怎么做?
答案 0 :(得分:25)
我检查了你的项目..无法解决正确的问题..
但是我尝试了一个黑客并且它有效..
用
替换此行[self presentModalViewController:navController animated:YES];
:此强>
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:navController animated:YES];