I'm still kinda new to this; so be gentle.
I want to download a setlist from flickr then select the following set and view its pictures.
Sp far I've contracted a way to get setlist. Now I want to be able to click one of the set lists and move to UICollectionsView
and view its images. I need help with being able to select the row in the UITableView
.
I think I'm missing a step somewhere but can't seem to find the hole I'm missing.
Anyway here's the code
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.rowHeight = 44;
photoURLs = [[NSMutableArray alloc] init];
photoSetNames = [[NSMutableArray alloc] init];
photoids = [[NSMutableArray alloc] init];
[self loadFlickrPhotos];
}
- (void)loadFlickrPhotos
{
// 1. Build your Flickr API request w/Flickr API key in FlickrAPIKey.h
NSString *urlString = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=%@&user_id=%@&per_page=10&format=json&nojsoncallback=1", FlickrAPIKey, @"62975213@N05"];
NSURL *url = [NSURL URLWithString:urlString];
// 2. Get URLResponse string & parse JSON to Foundation objects.
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
// NSDictionary *results = [jsonString JSONValue];
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
// 3. Pick thru results and build our arrays
NSArray *photosets = [[results objectForKey:@"photosets"] objectForKey:@"photoset"];
for (NSDictionary *photoset in photosets) {
// 3.a Get title for e/ photo
NSString *title = [[photoset objectForKey:@"title"] objectForKey:@"_content"];
[photoSetNames addObject:(title.length > 0 ? title : @"Untitled")];
NSString *photoid = [photoset objectForKey:@"id"];
[photoids addObject:photoid];
}
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"viewGallery"]){
flickrGalleryViewController *controller = (flickrGalleryViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
controller.photoids = [photoids objectAtIndex:indexPath.row];
NSLog(@"photoid = %@", controller.photoids);
}
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [photoSetNames count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell Identifier"];
cell.textLabel.text = [photoSetNames objectAtIndex:indexPath.row];
return cell;
}