0

I am trying to load images from Google Drive using google's example

- (void)loadDriveFiles {
  GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
  query.q = @"mimeType = 'image/png'";

  UIAlertView *alert = [DrEditUtilities showLoadingMessageWithTitle:@"Loading files"
                                                           delegate:self];
  [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                                            GTLDriveFileList *files,
                                                            NSError *error) {
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    if (error == nil) {
      if (self.driveFiles == nil) {
        self.driveFiles = [[NSMutableArray alloc] init];
      }
      [self.driveFiles removeAllObjects];
      [self.driveFiles addObjectsFromArray:files.items];
      [self.tableView reloadData];
    } else {
      NSLog(@"An error occurred: %@", error);
    //show error
    }
  }];
}

And Displaying it on table view as shown

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
     cell.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",file.title]];


}

It does not show the images, do I have to download the images first and if yes, could you please provide sample code.

  • [imageNamed](https://developer.apple.com/library/ios/documentation/uikit/reference/UIImage_Class/Reference/Reference.html) only works for images available in the main bundle, in your case you are downloading from the server so it will not work. Try using other resource e.g. [SDWebImage](https://github.com/rs/SDWebImage) – Janak Nirmal Jan 07 '14 at 04:50

3 Answers3

0

Are you missing a line in your cellForRowAtIndexPath method? The one that gets the file from the array of files pulled?

Something like:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

     GTLFile* file = [self.driveFiles objectAtIndex:indexPath.row];
     ...
}

Note: I'm guessing at the file type for the file variable here.

Then as someone else pointed out, are these files being downloaded somewhere locally? If so you want to load them using their full local path using:

[UIImage imageWithContentsOfFile:fullFilePath];

See UIImage Class Reference for other options.

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
valheru
  • 2,552
  • 3
  • 20
  • 40
0

Have a look at the following links:

  1. How to load images and display in a uitableview
  2. Load images asynchronously in a UITableView using GCD (Grand Central Dispatch)

I take no credit for the tutorials provided. These are already fantastic articles and I thought I'd point you in the right direction.

goodluck.

Community
  • 1
  • 1
Pavan
  • 17,840
  • 8
  • 59
  • 100
0

For future references, I found the answer I was looking for here Google Drive - Displaying images on uitableview