From d46524ff6d2761a22b49e6619a1815a6c290c3f3 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Sun, 6 Jan 2013 01:41:54 +0100 Subject: Added UITableViewDelegate and UITableViewDataSource to BeanCollectionBeanListViewController - stubs --- .../UserInterfaceState.xcuserstate | Bin 30432 -> 30411 bytes iBean/iBean/BeanCollectionBeanListViewController.h | 3 +- iBean/iBean/BeanCollectionBeanListViewController.m | 53 +++++++++++++++++++++ iBean/iBean/iPhoneStoryboard.storyboard | 12 ++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate index 0fe9ebe..4948f3e 100644 Binary files a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate and b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iBean/iBean/BeanCollectionBeanListViewController.h b/iBean/iBean/BeanCollectionBeanListViewController.h index 2441a48..5865904 100644 --- a/iBean/iBean/BeanCollectionBeanListViewController.h +++ b/iBean/iBean/BeanCollectionBeanListViewController.h @@ -9,7 +9,7 @@ #import @class BeanCollection; -@interface BeanCollectionBeanListViewController : UIViewController +@interface BeanCollectionBeanListViewController : UIViewController @property (nonatomic, strong) BeanCollection *beanCollection; @property (nonatomic, assign) BOOL editMode; @@ -19,6 +19,7 @@ - (void) initWithModeAndBeanCollection:(BOOL)editMode: (BeanCollection*) bc; /* UI Outlets */ +@property (weak, nonatomic) IBOutlet UITableView *beanListTableView; /* UI Actions */ diff --git a/iBean/iBean/BeanCollectionBeanListViewController.m b/iBean/iBean/BeanCollectionBeanListViewController.m index 8bc5085..4564776 100644 --- a/iBean/iBean/BeanCollectionBeanListViewController.m +++ b/iBean/iBean/BeanCollectionBeanListViewController.m @@ -52,6 +52,9 @@ { NSLog(@"BeanCollectionBeanListViewController - initViewController"); + //Load beans into the table view. + //[self.beanListTableView reloadData]; + if (self.editMode == YES) { //TODO: Update UI to refelect edit mode. @@ -70,6 +73,7 @@ NSLog(@"BeanCollectionBeanListViewController - initWithModeAndBeanCollection"); self.editMode = editMode; self.beanCollection = bc; + } /***************************************************** @@ -77,4 +81,53 @@ *****************************************************/ #pragma mark - IBActions +/***************************************************** + UITableView related delegate / datasource methods + *****************************************************/ +#pragma mark - UITableViewDelegate methods + +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return self.beanCollection.beans.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"BeanCell"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; + + //Configure the cell and set its title +#warning TODO: This may fuck things up since the beanCollection.beans set is NOT ordered? + BeanCollection *currentCollection = [[self.beanCollection.beans allObjects] objectAtIndex:indexPath.row]; + cell.textLabel.text = currentCollection.name; + + return cell; +} + +// Override to support conditional editing of the table view. +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Return NO if you do not want the specified item to be editable (we want to be able to REMOVE though). + return YES; +} + +// Override to support editing the table view. +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (editingStyle == UITableViewCellEditingStyleDelete) { + // Delete the row from the data source +#warning TODO - Implement this (look at CollectionList....) + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; + } + else if (editingStyle == UITableViewCellEditingStyleInsert) { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } +} + + @end diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index ce404ed..2f5d54b 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -287,6 +287,10 @@ + + + + @@ -306,6 +310,9 @@ + + + @@ -444,6 +451,9 @@ + + + @@ -481,6 +491,6 @@ - + \ No newline at end of file -- cgit v1.2.3