mpemburn
unread,Jun 3, 2012, 8:54:11 PM6/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to myLauncher
Hi All,
I've been having fun working with myLauncher the past couple of days.
My app has several categories of things (events, lists and videos)
that I want the user to be able to add to and remove from the
myLauncher pages as they wish. I call these things "push pin". The
code is split between the main myLauncher screen (the
DetailViewController of an iPad Split View app) and the "ListManager"
class that handles the lists of these entities. Here's how I'm doing
it:
* First, I had to expose some of the methods of MyLauncherView:
-(void)saveToUserDefaults:(id)object key:(NSString *)key;
-(void)savePages;
-(void)organizePages;
* Next, I subclassed ListManager to MyLauncherViewController. For
some reason, it would not access the the launcherView directly so I
added an instance of MyLauncherView:
MyLauncherView *launcherView;
.
.
.
launcherView = [[MyLauncherView alloc] init];
* When the user selects the "push pin" from the the list view, it
calls the following in ListManager:
- (void) setPushpin
{
NSMutableArray *currentItems = [self savedLauncherItems];
NSMutableArray *pageOne;
MyLauncherItem *newPushpin = [[MyLauncherItem alloc]
initWithTitle: @"Diane Selwyn"
iPhoneImage:
@""
iPadImage:
@"pinned_list"
target:
@"ItemViewController"
targetTitle :
@"Diane Selwyn"
deletable :
YES];
//*** See if there is already an array of myLauncher items.
// If not . . .
if ([currentItems count] == 0) {
//*** Create a new page and add the new item to it
pageOne = [[NSMutableArray alloc] init];
[pageOne addObject: newPushpin];
//*** Add page one to the collection of pages
[currentItems addObject: pageOne];
} else {
//*** Get the array for the existing first page
pageOne = [currentItems objectAtIndex: 0];
//*** If the page isn't full, stick the new item at the end
if ([pageOne count] < [launcherView maxItemsPerPage]) {
[pageOne addObject: newPushpin];
} else {
//*** Otherwise, stick the new item at the beginning
[pageOne insertObject: newPushpin atIndex: 0];
//*** . . . and let the launcherView organize things.
[launcherView organizePages];
}
}
[launcherView setPages: currentItems];
[launcherView savePages];
[popover dismissPopoverAnimated: YES];
[[NSNotificationCenter defaultCenter] postNotificationName:
@"PushpinAddedNotification" object: nil];
}
* Meanwhile, back at the DetailViewController, we've been listening
for a "PushpinAddedNotification":
[[NSNotificationCenter defaultCenter] addObserver:self selector:
@selector(refreshLauncher) name: @"PushpinAddedNotification" object:
nil];
* When we get the notification the myLauncher layout is refreshed:
- (void) refreshLauncher
{
[self.launcherView setPages:[self savedLauncherItems]];
[self.masterPopoverController dismissPopoverAnimated:YES];
}
I'd love to hear feedback and suggestions. Perhaps there's a cleaner
way to do this that as a relative noob, I might have missed.
Mark