Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:22:25+00:00 2026-05-31T04:22:25+00:00

I have a UITableViewController with a list of image names. When a name is

  • 0

I have a UITableViewController with a list of image names. When a name is clicked, the URL of the image is set in the ImageViewController and then the the UITableViewController segues to the ImageViewController that contains a UIImageView (connected with an outlet). In the ImageViewController‘s viewDidLoad I set the UIImageView to the image from the URL but when I run it on the simulator, only a black screen appears where the image should be.

A little visual description of the segue (where -> means segue):

  • ImageListTableViewController –> ImageViewController(has UIImageView)

ImageListTableViewController.m

// The delegate here is the ImageViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"Show Image"]) {
        [self setDelegate:segue.destinationViewController];
    }
}
// getting URL and calling the protocol method (in ImageViewController) which sets
// the image as an @property
#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *imageDict = [self.imageArray objectAtIndex:indexPath.row];
    NSURL *imageURL = [FlickrFetcher urlForPhoto:imageDict format:FlickrPhotoFormatLarge];
    NSLog([imageURL description]);
    [self.delegate imageListTableViewController:self withURL:imageURL];
}

ImageViewController.m

#import "ImageViewController.h"

@implementation ImageViewController

@synthesize image = _image;
@synthesize imageView = _imageView;

- (void)imageListTableViewController:(ImageListTableViewController *)sender 
                             withURL:(NSURL *)imageURL;
{
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
    self.image = [UIImage imageWithData:imageData];
}

#pragma mark - View lifecycle


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
  // nothing
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.imageView setImage:self.image];
}


- (void)viewDidUnload
{
    [self setImageView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

@end

Any ideas on what’s going on?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:22:27+00:00Added an answer on May 31, 2026 at 4:22 am

    Not really the right way to use a delegate. Try this:
    In ImageViewController.h:

    @property(nonatomic,strong) NSURL *imageURL;
    

    In ImageViewController.m

    @synthesize imageURL;
    

    Remove imageListTableViewController

    Change viewDidLoad:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
        self.image = [UIImage imageWithData:imageData];
    }
    

    Add to viewDidUnload:

    [self setImageURL:nil];
    

    Then in your ImageListTableViewController.m:
    Change prepareForSegue:

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"Show Image"]) {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            NSDictionary *imageDict = [self.imageArray objectAtIndex:indexPath.row];
            NSURL *imageURL = [FlickrFetcher urlForPhoto:imageDict format:FlickrPhotoFormatLarge];
    
            // Set the property on our Dest VC
            ImageViewController *ivc = segue.destinationViewController;
            ivc.imageURL = imageURL;
    
        }
    }
    

    Change your didSelectRowAtIndexPath:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [self performSegueWithIdentifier:@"Show Image" sender:nil];
    }
    

    Make sure you have connected that Segue to the VC itself and not to the TableView. If you don’t that Segue will get fired before didSelectRowAtIndexPath is fired. In this case, it won’t make a difference, but for real control – get in the habit of connecting to the VC and calling performSegue when needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableViewController subclass that renders a list of pre-set categories and fetches
Right now I have an UITableViewController that displays a set of Artist objects sorted
I have a simple UITableViewController in a UINavigationController that displays a list of strings
I have UITableViewController which contains a list of items. Now, I want the list
I have a UITableViewController that has a background image. I am setting the image
I have made a XML parser that list correctly in the UITableViewController. It passes
I have a UITableViewController. In viewDidLoad I set the rowHeight: self.tableView.rowHeight = 43; But
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have 8 cells that are being built in my UITableViewController. I would like
I have a UITableViewController that when opened displays a table of the following object:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.