我收到了与我对 iAd 使用 GKTurnBasedMatchmakerViewController 和 BannerViewController 相关的警告。该警告是:
Presenting view controllers on detached view controllers is discouraged <RootViewController: 0x14cd143c0>
下面显示的导致此警告的代码序列有什么问题?
在 AppDelegate.h
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *viewController;
}
在 AppDelegate.m
- (void) applicationDidFinishLaunching:(UIApplication*)application {
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[window setRootViewController:viewController];
[window addSubview: viewController.view];
}
然后当用户在我的主屏幕上按下 Play 按钮时,我首先打开游戏中心视图控制器,如下所示(注意第二行设置 presentingViewController 等于在 appDelegate 中设置的 rootViewController):
AppDelegate * theAppDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
self.presentingViewController = theAppDelegate.viewController;
GKTurnBasedMatchmakerViewController *mmvc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
[presentingViewController presentViewController: mmvc animated: YES completion:nil];
上述代码运行后,加载了一个新场景。这个场景在我的 GameSelectionLayer.h 中描述如下:
@interface GameSelectionLayer : CCLayer <InAppStoreControlLayerDelegate> {
...
RootViewController *viewController;
AppDelegate *app;
BannerViewController *bannerViewController;
}
然后在我的 GameSelectionLayer.mm 中,我加载bannerViewController onEnter,如下所示:
-(void)onEnter {
[super onEnter];
app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
viewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController];
bannerViewController = [[BannerViewController alloc] initWithContentViewController:viewController];
app.window.rootViewController = bannerViewController;
}
当上述代码运行时,我收到上述警告。请让我知道您认为我可能做错了什么导致此警告。