I am now using this code:
- (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];
}
Old method:
I am using the TTLauncherView
controller from http://three20.info.
Three20 is a collection of Objective-C classes that powers a growing number of popular applications on the App Store. It provides dozens of incredibly useful features that save you development time.
The library is built to be modular, which means you can selectively incorporate elements of the library into your project. There is also a growing set of extensions including drop-in XML and JSON parsing, as well as CSS stylesheet support for theming your applications.
I am not quite sure how to do the following:
- Check whether my
arrayOfLauncherItems
has 16 objects in it; and - If there are more than 16 objects, add the rest of the remaining objects to
_launcherView.pages
. So if let's say there's a total of 32 objects I'd want to be able to create another array of the remaining 16 objects and add them to the_launcherView.pages
NSArray
.
This is an example of how the TTLauncherView
controller works:
TTLauncherView *_launcherView = [[TTLauncherView alloc] initWithFrame:self.view.bounds];
NSMutableArray *arrayOfLauncherItems = [[NSMutableArray alloc] init];
//add TTLauncherItem objects to arrayOfLauncherItems.
_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, nil];
The arrayOfLauncherItems
may contain more than 16 objects, which means that the remaining TTLauncherItem
objects should be on the second page and so forth (depending on how many total objects there are).
Doing the following obviously adds the same 16 objects from arrayOfLauncherItems
, which means that there's now a second page, which is essentially what I want to achieve if there's more than 32 objects in arrayOfLauncherItems
.
_launcherView.pages = [NSArray arrayWithObjects:arrayOfLauncherItems, arrayOfLauncherItems, nil];