0

私は今このコードを使用しています:

- (void)loadLauncher:(NSMutableArray *)categoriesArray {
    _launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];
    _launcherView.columnCount = 3;

    // Number of pages in your launcherView.
    NSMutableArray *pages = [[NSMutableArray alloc] initWithCapacity:2];

    int numberOfObjects = [categoriesArray count];

    // The launcherItems in each page, calculate automatically the number of objects available for the launcher.
    NSMutableArray *launcherItems = [[NSMutableArray alloc] initWithCapacity:1];

    // The counter to identify if the number of objects exceeds the,
    // capacity of a launcher page of 9.
    int j = 1;

    for (int i = 0; i < numberOfObjects; i++){  
        if (j > 9){
            // Add the current launcherItems array to the pages.
            [pages addObject:launcherItems];

            // Initialise new launcher items.
            launcherItems = [[NSMutableArray alloc] initWithCapacity:1];

            // Start the counter again.
            j = 1;
        } else {  
            int i = 0;
            for (Category *c in categoriesArray) {
                NSString *categoryImage = [[NSString stringWithFormat:@"bundle://category_%@_icon.png", [Utility removeSpecialCharacters:@"&'- " withString:c.categoryName]] lowercaseString];
                NSLog(@" - %@", categoryImage);
                TTLauncherItem *launcherItem = [[[TTLauncherItem alloc] initWithTitle:c.categoryName
                                                                                image:categoryImage
                                                                                  URL:[NSString stringWithFormat:@"%d", i]
                                                                            canDelete:NO] autorelease];

                [launcherItems addObject:launcherItem];         

                i++;
            }
        }

        j++;
    }

    // Add the current launcherItems to the pages.
    [pages addObject:launcherItems];
    [launcherItems release];

    _launcherView.pages = pages;

    [self.view addSubview:_launcherView];
}

古い方法:

http://three20.infoTTLauncherViewのコントローラーを使用しています。

Three20 は、App Store で増え続ける人気アプリケーションを強化する Objective-C クラスのコレクションです。開発時間を節約する非常に便利な機能を多数提供します。

ライブラリはモジュール式に構築されているため、ライブラリの要素をプロジェクトに選択的に組み込むことができます。ドロップイン XML および JSON 解析、アプリケーションのテーマ設定のための CSS スタイルシート サポートなど、拡張機能のセットも増えています。

次のことを行う方法がよくわかりません。

  1. myarrayOfLauncherItemsに 16 個のオブジェクトがあるかどうかを確認します。と
  2. オブジェクトが 16 個を超える場合は、残りのオブジェクトを に追加します_launcherView.pages。したがって、合計 32 個のオブジェクトがあるとしたら、残りの 16 個のオブジェクトの別の配列を作成して、_launcherView.pages NSArray.

これは、TTLauncherViewコントローラーがどのように機能するかの例です。

TTLauncherView *_launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];

NSMutableArray *arrayOfLauncherItems = [[NSMutableArray alloc] init];
//add TTLauncherItem objects to arrayOfLauncherItems.

_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, nil];

arrayOfLauncherItemsには 16 個を超えるオブジェクトが含まれる場合があります。つまり、残りのオブジェクトTTLauncherItemは 2 ページ目に配置する必要があります (合計オブジェクト数に応じて)。

次の操作を行うと、明らかに同じ 16 個のオブジェクトが から追加されarrayOfLauncherItemsます。これは、2 ページ目があることを意味します。これは、基本的に、 に 32 個を超えるオブジェクトがある場合に達成したいことですarrayOfLauncherItems

_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, arrayOfLauncherItems, nil];
4

2 に答える 2

1

私はあなたが使用したいと思うかもしれない次のコードを持っています。基本的な考え方は、利用可能なオブジェクトの数に基づいてページ数を自動的に計算することです。各ページに 3x3=9 個のランチャー アイテムがあるとします。このように、オブジェクトの総数が 9 より少ないか多いかを気にする必要はありません。必要に応じて、この値を定数に入れることができます。

NSMutableArray *pages = [NSMutableArray array];
NSMutableArray *launcherItems = [NSMutableArray array];

//the counter to identify if the number of objects exceeds the
//capacity of a launcher page of 9
int j = 1;
for (int i = 0; i < numberOfObjects; i++){  

    TTLauncherItem *launcherItem = [[[TTLauncherItem alloc] initWithTitle: @"a title" 
                                                                    image: @"bundle://abc.png"
                                                                      URL: @"someUrlPath"
                                                                canDelete:TRUE] autorelease];
    [launcherItems addObject:launcherItem];         

    j++;

    if (j> 9){
        //add the current launcherItems to the pages
        [pages addObject:launcherItems];

        //initialize new launcher items
        launcherItems = [NSMutableArray array];
        //start again the counter
        j = 1;
    }       
}
//add the current launcherItems to the pages
[pages addObject:launcherItems];

_launcherView.pages = pages;
于 2010-12-06T14:05:07.277 に答える
1

1)[myArray count]配列内のアイテムの数を取得するために使用します。

2) for ループを使用します。

NSMutableArray *overflow = [NSMutableArray array];
NSMutableArray *sixteen = [NSMutableArray array];
for (int i = 16; i < [arrayOfLauncherItems count]; i++)
{
    [overflow addObject:[arrayOfLauncherItems objectAtIndex:i]];
}
for (int i = 0; i < 16; i++)
{
    [sixteen addObject:[arrayOfLauncherItems objectAtIndex:i]];
}

_launcherView.pages = [NSArray arrayWithObjects:sixteen, overflow, nil];

最初の for ループは、インデックス 16 から配列の最後までオブジェクトを追加し、それらを別の配列に追加します。2 番目は、元の配列の最初の 16 要素の配列になります。

于 2010-11-26T13:47:36.170 に答える