I want to display a tableview cell only if my AFNetworking request returns a json object as true. In this example I need place = "Store" to be true in order to display a table view which displays only stores.
the place = "Store" json is returned as part of my location_results array in the following request and I store it with self.place = [dictionary objectForKey:@"place"];
- (void)viewDidLoad
{
[super viewDidLoad];
// LoadLocations
[[LocationApiClient sharedInstance] getPath:@"locations.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id response) {
NSLog(@"Response: %@", response);
NSMutableArray *location_results = [NSMutableArray array];
for (id locationDictionary in response) {
Location *location = [[Location alloc] initWithDictionary:locationDictionary];
[location_results addObject:location];
}
self.location_results = location_results;
[self.tableView reloadData];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error fetching locations!");
NSLog(@"%@", error);
}];
I know I need to start by changing
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.location_results.count;
}
but not sure how.
Then I should be able to add a conditional statement to
- (LocationCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"LocationCell";
but not sure how.