我正在使用Vserv完整的sdk进行addintegeration。我正在调用我的adViewController来显示我的add.if失败的添加失败我从addViewController接受SplashViewController.But我收到此警告
Warning: Attempt to present <SplashViewController: 0x1dd697b0> on <AdViewController: 0x1dd68690>
whose view is not in the window hierarchy!
并且无法导航到我的下一个视图SplashViewController ..我尝试过以下所有方法都是代码。你们可以帮我解决一下:
AdViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if([Util isInternetAvailable])
{
//Initializes SDK
[VservAdManager initializeSDK];
CGRect frame1;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
frame1 = CGRectMake(0,0,1024,768);
else
frame1 = CGRectMake(0,0,320,480);
vservAdView = [[VservAdView alloc] initWithFrame:frame1];
[vservAdView requestAd:self:@"7825":nil];
[self.view addSubview: vservAdView];
}
else{
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = appDelegate.splashViewController;
[self presentModalViewController:appDelegate.splashViewController animated:NO];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
else {
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
}
- (void)adReceivedNotification:(VservAdView*)vservAd{
NSLog(@"adReceivedNotification");
}
- (void)adFailedNotification:(VservAdView*)vservAd{
NSLog(@"adFailedNotification");
appDelegate.window.rootViewController = appDelegate.splashViewController;
[self presentViewController:appDelegate.splashViewController animated:NO completion:Nil];
}
- (void)adSkipedNotification:(VservAdView*)vservAd{
NSLog(@"adSkipedNotification");
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = appDelegate.splashViewController;
[self presentModalViewController:appDelegate.splashViewController animated:NO];
}
SplashViewController.h
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self setupMovie];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
else {
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
}
-(void)setupMovie{
NSLog(@"setup Movie");
NSString* moviePath = [[NSBundle mainBundle] pathForResource:@"Splash" ofType:@"mp4"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
playerCtrl = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
// playerCtrl.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
[playerCtrl.view setFrame:CGRectMake(0, 0, 1024, 768)];
}
else{
[playerCtrl.view setFrame:CGRectMake(0, 120, 320, 240)];
}
// [playerCtrl.view setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
[self.view addSubview:playerCtrl.view];
[playerCtrl setRepeatMode:MPMovieRepeatModeNone];
[playerCtrl play];
}
-(IBAction)moviePlayBackDidFinish:(id)sender{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[self presentModalViewController:appDelegate.revealController animated:NO];
appDelegate.window.rootViewController = appDelegate.revealController;
}
答案 0 :(得分:0)
如果将窗口的根视图设置为splashViewController,为什么要在self上显示视图?
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = appDelegate.splashViewController;
[self presentModalViewController:appDelegate.splashViewController animated:NO];
改为使用此
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
//appDelegate.window.rootViewController = appDelegate.splashViewController;
[appDelegate.window presentModalViewController:appDelegate.splashViewController animated:NO];