Cocos2d iPhone アプリケーションでこれを行ったとき、NSTableView
.
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html
Cocos2d で Cocoa インターフェイス クラスを使用するには、理解しなければならないことがいくつかありますが、それだけの価値はあります。結果を確認したい場合は、Crystal Shuffle でこれらを使用しました。
アイテムはタッチ イベントに応答でき、それらのイベントを取得したときにポップアップを実行できます。そのために、Cocoa インターフェイス クラスも使用します。私の場合、NSAlert クラスを使用しました。
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSAlert_Class/Reference/Reference.html
Cocos2d バージョン 0.99.3 を使用して、UITableView を使用するためのコード例:
@interface MyMenu : CCLayer <UITableViewDelegate, UITableViewDataSource>
{
UITableView* m_myTableView;
}
@implementation MyMenu
-(void) onEnter
{
m_myTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 250, 120) style:UITableViewStylePlain];
m_myTableView.delegate = self;
m_myTableView.dataSource = self;
m_myTableView.backgroundColor = [UIColor clearColor];
m_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
m_myTableView.rowHeight = 27;
m_myTableView.allowsSelection = NO;
}
-(void)onEnterTransitionDidFinish
{
[super onEnterTransitionDidFinish];
[[[CCDirector sharedDirector] openGLView] addSubview:m_myTableView];
[m_myTableView release];
}
レイヤーを閉じる前に呼び出すには:
NSArray *subviews = [[[CCDirector sharedDirector] openGLView] subviews];
for (id sv in subviews)
{
if(((UIView*)sv).tag == e_myTableTag)
{
[((UITableView*)sv) removeFromSuperview];
}
}
関連するオーバーロードも必要です。これは、Apple のドキュメントで調べることができます。
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath