【发布时间】:2010-11-26 13:33:55
【问题描述】:
我现在正在使用这个代码:
- (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.info 的TTLauncherView 控制器。
Three20 是一个 Objective-C 类的集合,它为 App Store 上越来越多的流行应用程序提供支持。它提供了许多非常有用的功能,可以节省您的开发时间。
该库是模块化构建的,这意味着您可以有选择地将库的元素合并到您的项目中。还有一组不断增长的扩展,包括插入式 XML 和 JSON 解析,以及用于主题化应用程序的 CSS 样式表支持。
我不太确定如何执行以下操作:
- 检查我的
arrayOfLauncherItems里面是否有16个对象;和 - 如果对象超过 16 个,则将剩余的对象添加到
_launcherView.pages。因此,如果假设总共有 32 个对象,我希望能够创建剩余 16 个对象的另一个数组并将它们添加到_launcherView.pagesNSArray。
这是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 对象应位于第二页,依此类推(取决于总共有多少对象)。
执行以下操作显然会从arrayOfLauncherItems 添加相同的16 个对象,这意味着现在有第二个页面,如果arrayOfLauncherItems 中有超过32 个对象,这基本上是我想要实现的。
_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, arrayOfLauncherItems, nil];
【问题讨论】:
标签: objective-c nsmutablearray nsarray three20 ttlauncherview