Skip to content
Browse files

Friends loaded into UITableView (within UIViewController)

Loading View (via tableView hiding) created to handle waiting for FBook
API didLoad method in order to populate Table View.
  • Loading branch information...
1 parent b9c312e commit 3180aee564feecab4423649fddc1d4834f990258 @cameronB committed
View
4 ClubIn.xcodeproj/project.pbxproj
@@ -51,6 +51,7 @@
9E2B5BFF1570F5CD00123B05 /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E2B5BFE1570F5CD00123B05 /* DetailViewController.m */; };
9E2B5C0215711E8900123B05 /* ClubMapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E2B5C0115711E8900123B05 /* ClubMapViewController.m */; };
9EC96EB515860B09002A9D44 /* FriendsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EC96EB415860B09002A9D44 /* FriendsViewController.m */; };
+ 9EC96ECB1588B004002A9D44 /* MenuButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 9EC96ECA1588B004002A9D44 /* MenuButton.png */; };
9EDCE27D157A1FCB0033E912 /* HeadingHereViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EDCE27C157A1FCB0033E912 /* HeadingHereViewController.m */; };
/* End PBXBuildFile section */
@@ -138,6 +139,7 @@
9E2B5C0115711E8900123B05 /* ClubMapViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ClubMapViewController.m; sourceTree = "<group>"; };
9EC96EB315860B09002A9D44 /* FriendsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FriendsViewController.h; sourceTree = "<group>"; };
9EC96EB415860B09002A9D44 /* FriendsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FriendsViewController.m; sourceTree = "<group>"; };
+ 9EC96ECA1588B004002A9D44 /* MenuButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MenuButton.png; sourceTree = "<group>"; };
9EDCE27B157A1FCB0033E912 /* HeadingHereViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeadingHereViewController.h; sourceTree = "<group>"; };
9EDCE27C157A1FCB0033E912 /* HeadingHereViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HeadingHereViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -326,6 +328,7 @@
9E2B5BD41570D40100123B05 /* Images */ = {
isa = PBXGroup;
children = (
+ 9EC96ECA1588B004002A9D44 /* MenuButton.png */,
9E2B5BE11570D4DB00123B05 /* logoR.png */,
9E2B5BD51570D42800123B05 /* 24_info.png */,
9E2B5BD61570D42800123B05 /* arrow.png */,
@@ -457,6 +460,7 @@
9E2B5BDE1570D42800123B05 /* logo.png in Resources */,
9E2B5BE01570D42800123B05 /* pin.png in Resources */,
9E2B5BE21570D4DB00123B05 /* logoR.png in Resources */,
+ 9EC96ECB1588B004002A9D44 /* MenuButton.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN .../project.xcworkspace/xcuserdata/cameronbradley.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
21 ClubIn/FriendsViewController.h
@@ -9,9 +9,28 @@
#import <UIKit/UIKit.h>
#import "FBConnect.h"
#import "AppDelegate.h"
+#import "PullRefreshTableViewController.h"
-@interface FriendsViewController : UITableViewController <FBSessionDelegate, FBDialogDelegate, FBRequestDelegate> {
+@interface FriendsViewController : UIViewController <FBSessionDelegate, FBDialogDelegate, FBRequestDelegate, UITableViewDataSource, UITableViewDelegate> {
+ //array to store the API graph results for me/friends.
+ NSArray *items;
+
+ //store facebook friends Id in NSMutableArrays
+ NSMutableArray *friendIds;
+ NSMutableArray *friendNames;
+
+ //UIElements for..
+ UILabel *loadingLabel;
+ UITableView *menuTableView;
+ UIActivityIndicatorView *activityIndicator;
}
+@property (nonatomic, retain) NSArray *items;
+@property (nonatomic, retain) NSMutableArray *friendIds;
+@property (nonatomic, retain) NSMutableArray *friendNames;
+@property (nonatomic, retain) UILabel *loadingLabel;
+@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
+@property (nonatomic, retain) UITableView *menuTableView;
+
@end
View
242 ClubIn/FriendsViewController.m
@@ -10,15 +10,130 @@
@implementation FriendsViewController
+@synthesize friendIds;
+@synthesize friendNames;
+@synthesize items;
+@synthesize loadingLabel;
+@synthesize activityIndicator;
+@synthesize menuTableView;
+
+-(void)dealloc {
+ [friendIds release];
+ [friendNames release];
+ [items release];
+ [loadingLabel release];
+ [activityIndicator release];
+ [menuTableView release];
+ [super dealloc];
+}
--(void)viewDidLoad {
+//initilize view programmatically
+- (void) loadView {
+
+ //allocate view
+ UIView *view = [[UIView alloc] initWithFrame:[UIScreen
+ mainScreen].applicationFrame];
+
+ //add background default_bg image to view
+ view.backgroundColor = [UIColor whiteColor];
+
+ self.view = view;
+ [view release];
+ //allocate Table View to view and hide it on load.
+ menuTableView = [[UITableView alloc] initWithFrame:self.view.bounds
+ style:UITableViewStylePlain];
+ [menuTableView setBackgroundColor:[UIColor whiteColor]];
+ menuTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
+ menuTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ menuTableView.dataSource = self;
+ menuTableView.delegate = self;
+ menuTableView.hidden = YES;
+ [self.view addSubview:menuTableView];
+
+ // loading label display on load
+ loadingLabel = [[UILabel alloc]
+ initWithFrame:CGRectMake(7.0, 2.5, 85.0, 40.0)];
+ loadingLabel.textAlignment = UITextAlignmentCenter;
+ loadingLabel.textColor = [UIColor blueColor];
+ loadingLabel.backgroundColor = [UIColor clearColor];
+ //set text as selected club.
+ loadingLabel.text = @"Loading....";
+ //add lblClubLabel to headbar subview.
+ [self.view addSubview:loadingLabel];
+
+ // Activity Indicator display on load.
+ activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(92.0, 3.5, 30, 30)];
+ activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
+ //add activity indicator to subview
+ [self.view addSubview:activityIndicator];
+ //call method to show the activity indicator on load.
+ [self showActivityIndicator];
+}
+
+-(void)viewDidLoad {
+
//set the navigation bar item title.
- self.navigationItem.title = @"Fellow Clubbers";
+ self.navigationItem.title = @"Friends";
+ //graph the logged in users friends.
[self apiGraphFriends];
}
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+
+}
+
+//This method hides the table view (for showing loading)
+- (void)showLoadingView {
+
+ //hide the UITableView.
+ menuTableView.hidden = YES;
+
+ //show the loading label.
+ loadingLabel.hidden = NO;
+
+ //show the activity indicator.
+ [self showActivityIndicator];
+
+ //reload the table view.
+ [self.menuTableView reloadData];
+
+}
+
+//This method shows the table view (when data is loaded)
+- (void)hideLoadingView {
+
+ //show the UITableView
+ menuTableView.hidden = NO;
+
+ //hide the loading label.
+ loadingLabel.hidden = YES;
+
+ //hide the activity indicator.
+ [self hideActivityIndicator];
+
+ //reload the table view.
+ [self.menuTableView reloadData];
+}
+
+//This method shows the activity indicator
+- (void)showActivityIndicator {
+ if (![activityIndicator isAnimating]) {
+ [activityIndicator startAnimating];
+ }
+}
+
+//This method hides the activity indicator
+- (void)hideActivityIndicator {
+ if ([activityIndicator isAnimating]) {
+ [activityIndicator stopAnimating];
+ }
+
+}
+
#pragma mark - Facebook API Calls
/*
* Graph API: Method to get the user's friends.
@@ -28,109 +143,84 @@ - (void)apiGraphFriends {
// Do not set current API as this is commonly called by other methods
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithGraphPath:@"me/friends" andDelegate:self];
-
}
- (void)request:(FBRequest *)request didLoad:(id)result {
- NSLog(@"%@", result);
-
- if ([result isKindOfClass:[NSArray class]] && ([result count] > 0)) {
- result = [result objectAtIndex:0];
- }
-
- int test = [result count];
+ /*https://graph.facebook.com/me/friends?limit=5000&offset=0&format=json&access_token=BAADAMvDi7X0BAK2SErYztSTsvKjuQqMkWbdk364Xib4WNPAZAJceZCwIoeMM6ZCZAwQNnEpszCokHsStJKtlpO56jULLoyFAcBrn4zvQi1iaIdF4YZBtxIcjEmx6jyKoZD*/
+
+ //allocate NSMutableArrays
+ friendIds = [[NSMutableArray alloc] init];
+ friendNames = [[NSMutableArray alloc] init];
- if ([result count] > 0) {
- NSLog(@"found friends%i ", test);
- } else {
- NSLog(@"no friends found");
+ items = [[(NSDictionary *)result objectForKey:@"data"]retain];
+ for (int i=0; i<[items count]; i++) {
+ NSDictionary *friend = [items objectAtIndex:i];
+ [friendIds addObject:[friend objectForKey:@"id"]];
+ [friendNames addObject:[friend objectForKey:@"name"]];
}
-}
-
-- (void)viewDidUnload
-{
- [super viewDidUnload];
+ //hide the activity indicator
+ [self hideLoadingView];
}
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
-{
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
+//adjust height for table cell.
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+ //height of cell
+ return 80.0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
- return 0;
+ return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
- return 0;
+ return [friendIds count];
}
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-{
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+//table view cell styles.
+-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- // Configure the cell...
+ //set the background image for the cell.
+ cell.backgroundColor = [UIColor whiteColor];
- 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.
- 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
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: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
- }
+ //textLabel styles.
+ cell.textLabel.backgroundColor = [UIColor clearColor];
+ cell.textLabel.font = [UIFont systemFontOfSize:16.0];
+ cell.textLabel.textColor = [UIColor blueColor];
+
+ //detailTextLabel styles.
+ cell.detailTextLabel.backgroundColor = [UIColor clearColor];
+ cell.detailTextLabel.font = [UIFont systemFontOfSize:10.0];
+ cell.detailTextLabel.textColor = [UIColor blueColor];
}
-*/
-/*
-// Override to support rearranging the table view.
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
-{
-}
-*/
-/*
-// Override to support conditional rearranging of the table view.
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- // Return NO if you do not want the item to be re-orderable.
- return YES;
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease];
+ //set Selection style (when button is pressed).
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ //set the accessory type (the button on the cell) to none.
+ cell.accessoryType = UITableViewCellSelectionStyleNone;
+
+ }
+
+ //set the textLabel as the clubName.
+ cell.textLabel.text = [friendNames objectAtIndex:indexPath.row];
+
+ return cell;
}
-*/
-
-#pragma mark - Table view delegate
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
- // Navigation logic may go here. Create and push another view controller.
- /*
- <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
- // ...
- // Pass the selected object to the new view controller.
- [self.navigationController pushViewController:detailViewController animated:YES];
- [detailViewController release];
- */
+ //only allow portrait orientation.
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
View
BIN ClubIn/MenuButton.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3180aee

Please sign in to comment.
Something went wrong with that request. Please try again.