在多个UIViewController和OpenGLView(Cocos2D)之上,显示透明的UITableView

4

这是我的代码:

// View Controller with navigation bar
InAppPurchaseViewController *purchaseViewController = [[InAppPurchaseViewController alloc] init];
purchaseViewController.title = @"Magasin";
purchaseViewController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissViewController:)] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:purchaseViewController] autorelease];

// Add `purchaseViewcontroller` TO container AND container ON openGLView
UIViewController *container = [[UIViewController alloc] init];
[container setView:[[CCDirector sharedDirector] openGLView]];
[container setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
[container presentViewController:navController animated:YES completion:nil];

UITableView在purchaseViewController中。

我曾考虑使用[UIColor clearColor],但不管我用它在哪里,我的UITableView都有黑色背景。单元格变得不可选择和滑动(除了单元格内的元素)。

编辑:appdelegate

这是.h文件。

@class AudioEngine;
@class RootViewController;
@class Score;

@interface AppDelegate : NSObject <UIApplicationDelegate, GameCenterManagerDelegate>

@property int CurrentPackage;
@property int CurrentScore;
@property int CurrentHighScore;
@property BOOL SoundShouldPlay;
@property BOOL PauseScreenUp;
@property(nonatomic, retain) AudioEngine *CustomAudioEngine;
@property(nonatomic, retain) GameCenterManager *CustomGameCenterManager;
@property(nonatomic, retain) UIWindow *window;
@property(nonatomic, readonly) RootViewController *ViewController;
@property(nonatomic, retain) NSString* CurrentLeaderBoard;
@property(nonatomic, retain) NSMutableArray *TenLastScoresArray;

+(AppDelegate *)get;
-(void)connectToGameCenter;
-(void)addScoreToLastScore:(Score*)score;

方法已经完成启动

-(void)applicationDidFinishLaunching:(UIApplication*)application
{
    CC_DIRECTOR_INIT();
    self.CurrentLeaderBoard = kLeaderboardID;
    [[SKPaymentQueue defaultQueue] addTransactionObserver:[InAppPurchaseSingleton sharedHelper]];
    [AudioEngine preloadBackgroundMusic];
    [AudioEngine playBackgroundMusic:3];
    self.SoundShouldPlay = YES;
    [SceneManager goSplash];
}

将tableview对象的clear color属性设置为透明。 - Nims
尝试以下操作:1- 为 UITableViewUITableViewCell 设置背景为 [UIColor clearColor]。2- 为 UITableViewUITableViewCell 设置 OpaqueNO - Mazyod
你试过不执行 [container setView:[[CCDirector sharedDirector] openGLView]]; 然后看看会发生什么吗?只是为了澄清一下是否存在 UITableView 和 Cocos2D 之间的某种故障... - sergio
如果我不设置openGLView,模态UIViewController就不会显示出来。基本上什么都不会发生 =/ - An-droid
1个回答

3

不要在container上呈现视图控制器:

UIViewController *container = [[UIViewController alloc] init];
...
[container presentViewController:navController animated:YES completion:nil];

在Cocos2D模板创建的根视图控制器上显示应该是可行的。通常可以通过应用程序代理访问:

UIViewController *rootViewController = (UIViewController*)[(YOURAPPDELEGATE*)[[UIApplication sharedApplication] delegate] viewController];
[rootViewController presentViewController:navController animated:YES completion:nil];

viewController 是 cocos2D 默认模板添加到应用程序委托类中的实例变量。它通常是私有的,因此您需要定义一个访问器:

@property (nonatomic, readonly) RootViewController *viewController; //-- .h file

@synthesize viewController; //-- .m file

希望这能有所帮助。
编辑:
根据我的应用程序委托中的内容,我认为您可以尝试像这样实例化RootViewController:
    CC_DIRECTOR_INIT
ViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
ViewController.wantsFullScreenLayout = YES;
[ViewController setView:[[CCDirector sharedDirector] openGLView]];
    ...

第一行中的“viewController”是什么? - An-droid
所以我很快地尝试了一下,但似乎还不够。目前我的应用程序是基于OpenGLView的(我使用coco2d场景和图层,并在其上方弹出视图控制器)。问题是我不想做相反的事情...使用这个rootViewController方法,当我按下“PurchaseButton”时什么也没有发生,我不知道为什么。没有错误... - An-droid
请您能否提供您的应用程序委托接口定义和appDidFinishLoading方法的具体内容?我使用该方法并且它有效,所以可能是您的viewController成员出了问题。在您呈现其他视图控制器时,您是否检查过它不是空值(nil)? - sergio
你使用的是哪个版本的Cocos2D? - sergio
我使用V1.0.0,你为什么问? - An-droid
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接