Skip to content

Instantly share code, notes, and snippets.

@jfahrenkrug
Created September 8, 2009 14:09
Show Gist options
  • Save jfahrenkrug/182942 to your computer and use it in GitHub Desktop.
Save jfahrenkrug/182942 to your computer and use it in GitHub Desktop.
- (void)addLocation {
if (!locations) {
locations = [[CPArray alloc] init];
}
loc = [[Location alloc] init];
[loc setDescription:@""];
[loc setPosition:([locations count] + 1)];
[locations addObject:loc];
[locationListView setContent:locations];
[locationListView reloadContent];
[locationListView setSelectionIndexes:[CPIndexSet indexSetWithIndex:([locations count] - 1)]];
}
- (void)removeLocation {
if (![self selectedLocation]) {
return;
}
if (confirm('Are you sure?'))
{
if ([[self selectedLocation] isNewRecord]) {
[self removeSelectedLocation];
} else {
//we'll implement this later
}
}
}
- (void)removeSelectedLocation {
[locations removeObjectAtIndex:[[locationListView selectionIndexes] firstIndex]];
[locationListView setContent:locations];
[locationListView reloadContent];
[locationListView setSelectionIndexes:[CPIndexSet indexSetWithIndex:([locations count] - 1)]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment