Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNavid Mirzaie Milani
6,274 PointsCalling a method from a class in a UITableViewController
Hi there best treehouse members,
i've a question about calling a method from my class into the UITableViewController, in this method called: loadData i've made connection to my localhost and getting a json object, the implementation of this method works so don't need to worry about that and when i NSLog it gives me the correct output.
The strange thing is when i'm calling this method into my ViewDidLoad method in my TableViewController i don't get anything back, how is this possible? Because when i'm move my method into the .h file of TableViewController and implement it to my TableViewController.m then it works.
Here an example.
@interface CLub : NSObject
@property(nonatomic,strong) NSMutableArray *teams;
@property(nonatomic,strong) NSString *teamName;
-(void)loadData;
@end
@implementation CLub
-(void)loadData {
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost/xampp/flashbackapi/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.club.teams = [[NSMutableArray alloc] init];
self.club.teams = [responseObject objectForKey:@"clubs"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error %@ %@",error,error.userInfo);
}];
[operation start];
}
@end
@implementation ClubsTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.club = [[CLub alloc]init];
[self.club loadData];
}
Thanks in advanced.