我正在使用Cocos2d製作iOS遊戲,並且需要自定義UITableView的外觀。看起來this post提供了一個很好的框架,並且我自己測試時,示例代碼運行良好。問題是我無法在我的cocos2d應用程序中運行它。Cocos2d中的自定義UIView-iphone
示例使用此代碼來創建自定義的UIViewController:(窗口是一個UIWindow和ViewController是EasyCustomTableController)
[window addSubview:viewController.view];
[window makeKeyAndVisible];
但是當我使用的代碼,該EasyCustomTableController的viewDidLoad函數從不運行,並沒有任何反應在我的遊戲中。我能得到的viewDidLoad功能通過使用此代碼運行:
levelMenu = [[EasyCustomTableController alloc] init];
[[[CCDirector sharedDirector] openGLView] addSubview:levelMenu.view];
但同樣的,什麼也沒有發生在我的遊戲和觀點從未出現。
如何獲得自定義UIViewController在我的cocos2d應用程序中工作?
編輯:
我可以得到一個UIView以白色背景來顯示,所以必須與levelMenu.view一個問題:
UIApplication* clientApp = [UIApplication sharedApplication];
UIWindow* topWindow = [clientApp keyWindow];
if (!topWindow) {
topWindow = [[clientApp windows] objectAtIndex:0];
}
//Works
UIView *white = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
white.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:255];
[topWindow addSubview:white];
//Doesn't work
levelMenu = [[EasyCustomTableController alloc] init];
[topWindow addSubview:levelMenu.view];
我沒有從改變levelMenu的類代碼樣本 - 你可以看到viewDidLoad中的第一個代碼框中here
viewDidLoad運行,我的遊戲停止處理輸入,但表視圖仍然沒有出現。 – Cbas
在'viewDidLoad'中嘗試'bringSubviewToFront:'。還要確保'view.frame'是正確的 –
我的編輯中的新代碼應該將視圖置於前面。我嘗試設置levelMenu.tableView.frame來適應屏幕,但這並沒有改變什麼 – Cbas