Skip to content

Instantly share code, notes, and snippets.

@Jarada
Created July 1, 2012 14:50
Show Gist options
  • Save Jarada/3028664 to your computer and use it in GitHub Desktop.
Save Jarada/3028664 to your computer and use it in GitHub Desktop.
myLauncher - adding a myLauncherItem
// This is an example coding gist for use on myLauncher Google Groups to explain how add an item to myLauncherView
// This is just a temporary workaround for new code coming soon
/*
RootViewController - represents the RootViewController that extends MyLauncherViewController
*/
@implementation RootViewController
/*
Add's an item to myLauncherView (first to the end of the last page, then to another page, then to any space available)
*/
- (void)addItem:(MyLauncherItem *)item {
NSMutableArray *pages = [[self.launcherView pages] copy];
// Get the last page, check it's size and add to it if possible
if ([[pages objectAtIndex:[pages count] - 1] count] < [self.launcherView maxItemsPerPage]) {
NSMutableArray *page = [pages objectAtIndex:[pages count] - 1];
[page addObject:item];
[self.launcherView setPages:pages animated:YES];
return;
}
// Next, check if we can add it to the end
if ([pages count] < [self.launcherView maxPages]) {
NSMutableArray *page = [[NSMutableArray alloc] init];
[page addObject:item];
[pages addObject:page];
[self.launcherView setPages:pages animated:YES];
return;
}
// Finally, go back and see if we can add it anywhere there is room
for (int x = [pages count] - 2; x >= 0; x--) {
if ([[pages objectAtIndex:x] count] < [self.launcherView maxItemsPerPage]) {
[[pages objectAtIndex:x] addObject:item];
[self.launcherView setPages:pages animated:YES];
break;
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment