0

これはちょっとややこしい質問ですが、できる限り説明しようと思います。

私が欲しいのは、サイズが設定されたボックスです。そのボックス内に、上部にテキスト行が追加されます。アプリが進むにつれて、最後の行の下にさらに行が追加されます。テキストがボックスの一番下に達すると、テキストのリストを下にスクロールするまで表示されません。つまり、テキストのすべての行がボックスに含まれるようにします。

また、特定のテキスト行がクリックされたときにポップアップするメッセージが必要です。

これを達成するための最良の方法は何ですか?

前もって感謝します!

4

1 に答える 1

1

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
于 2012-05-16T14:22:48.257 に答える