Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

iphone - Whose view is not in window hierarchy issue

I've set up a navController, which appears after tapping a button. However, if I tap the button I get the error of: "Warning: Attempt to present <UINavigationController>: 0xab5d9d0 on <MyApp: 0xadaa320> whose view is not in the window hierarchy!"

Does anyone know how to solve this? I also tried something on Stackoverflow but it wasn't my solution.

Here my code for opening the navigationcontroller:

I dont know if somebody know this photogallery but if you don't, here is the project.

My code (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];
}

Thanks in advance.

Edit:

it is in the recources and in the compile sources but in the resources you can see that it is red (the storyboard). Maybe it's caused by this?

The Second controller .h:

@class MyApp;

@interface Second : UIViewController <MWPhotoBrowserDelegate> {

}



@property (nonatomic, retain) MyApp* vC;

@end

The Secnond 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;

enter image description here

NEW EDIT:

I found that I have to call the method "launchGalleryView" in the viewDidAppear but how can I do this without calling the navcontroller everytime the view loads? Does anyone know how to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i checked your project.. wasn't able to sort out the proper issue..

but i tried a hack and it worked..

replace this line with

[self presentModalViewController:navController animated:YES];

this

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:navController animated:YES];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...