私は今このコードを使用しています:
- (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 スタイルシート サポートなど、拡張機能のセットも増えています。
次のことを行う方法がよくわかりません。
- my
arrayOfLauncherItems
に 16 個のオブジェクトがあるかどうかを確認します。と - オブジェクトが 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];