Browse files

Allow adding of resorts

  • Loading branch information...
1 parent 7b1af4f commit b4ca7c2c5308e7db196c382d5d54974760aced80 Bryce Hammond committed Feb 28, 2012
View
16 Powder/Code/PowderFavoritesEditViewController.m
@@ -95,7 +95,21 @@ - (void)resortsViewControllerDidCancel:(PowderResortsViewController *)controller
- (void)resortsViewController:(PowderResortsViewController *)controller didSelectResort:(Resort *)resort
{
- //Nothing for now
+ //add the favorite to the end
+ Favorite *favorite = [[Favorite alloc] init];
+ favorite.resortName = resort.name;
+ favorite.resortID = resort.snowReportID;
+ [self.favorites addObject:favorite];
+
+ //update the data API
+ [[PowderAPI sharedInstance] setFavorites:self.favorites];
+
+ //update the UI
+ NSIndexPath *updateIndex = [NSIndexPath indexPathForRow:([self.favorites count] - 1) inSection:0];
+ [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:updateIndex]
+ withRowAnimation:UITableViewRowAnimationAutomatic];
+
+ [self dismissModalViewControllerAnimated:YES];
}
#pragma mark - UITableViewDelegate methods
View
2 Powder/Code/PowderResortsViewController.h
@@ -20,7 +20,7 @@
@property (weak, nonatomic) IBOutlet UITableView *tableView;
-@property (weak, nonatomic) IBOutlet id <PowderResortsViewControllerDelegate> delegate;
+@property (weak, nonatomic) IBOutlet id<PowderResortsViewControllerDelegate> delegate;
@property (weak, nonatomic) IBOutlet UIButton *addRemoveButton;
@property (weak, nonatomic) IBOutlet UILabel *resortNameLabel;
View
8 Powder/Code/PowderResortsViewController.m
@@ -98,6 +98,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ NSString *state = [[[PowderAPI sharedInstance] states] objectAtIndex:indexPath.section];
+ Resort *resort = [[[PowderAPI sharedInstance] resortsInState:state] objectAtIndex:indexPath.row];
+
+ [self.delegate resortsViewController:self didSelectResort:resort];
+}
+
#pragma mark - UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

0 comments on commit b4ca7c2

Please sign in to comment.