我现在使用以下代码:
- (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];
}旧方法:
我正在使用来自TTLauncherView的http://three20.info控制器。
Three20是Objective类的集合,它为App上越来越多的流行应用程序提供了动力。它提供了数十个非常有用的特性,为您节省了开发时间。
库是模块化的,这意味着您可以有选择地将库的元素合并到您的项目中。还有越来越多的扩展,包括插入XML和JSON解析,以及对应用程序主题化的CSS样式表支持。
我不太清楚如何做到以下几点:
arrayOfLauncherItems中是否有16个对象;如果有超过16个对象,则_launcherView.pages中。因此,如果我们假设总共有32个对象,我希望能够为剩下的16个对象创建另一个数组并将它们添加到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对象应该在第二个页面上,依此类推(取决于总共有多少个对象)。
执行以下操作显然会从arrayOfLauncherItems中添加相同的16个对象,这意味着现在有了第二个页面,如果arrayOfLauncherItems中有超过32个对象,这基本上就是我想要实现的。
_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, arrayOfLauncherItems, nil];发布于 2010-12-06 14:05:07
我有下面的代码,您可能想要使用。基本思想是根据可用对象的数量自动计算页面数。我假设每个页面中都有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-11-26 13:47:36
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添加到数组的末尾,并将它们添加到另一个数组中。第二个以原始数组的前16个元素的数组结束。
https://stackoverflow.com/questions/4285722
复制相似问题