Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Split view controller - changing image in detailViewController
    primarykey
    data
    text
    <p>This is another of those "I'm sure there's an easy answer to this" questions, but I find myself baffled.</p> <p>I'm using the split view controller from the template. I'm successfully passing a NSString to the _detailItem variable, but am unable to use it to create and load an image into an UIImageView (named "stripImage"). </p> <p>It works up until: <strong>[self.stripImage setImage:[UIImage imageNamed: _detailItem]];</strong></p> <p>If I put a string literal into the same line of code (like @"image20.jpg"), it works fine.</p> <pre><code>- (void)configureView { // Update the user interface for the detail item. if (self.detailItem) { NSLog(@"_detailItem is still: %@",_detailItem); // correctly reports the name of the imagefile (for example: "image20.jpg" [self.stripImage setImage:[UIImage imageNamed: _detailItem]]; NSLog(@"The image being shown is: %@",self.stripImage.image); //returns "The image being shown is: (null)" } } </code></pre> <p>Please help keep my head from exploding. Thanks in advance.</p> <h2>... and I've tried it this way:</h2> <h2>(in my Master view controller):</h2> <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Selected row %i",[indexPath row]); NSString *imageName = [[stories objectAtIndex:[indexPath row]] objectForKey:@"link"]; NSLog(@"The image is: %@", imageName); // These two work, oddly enough... self.detailViewController.detailTitle.text = [[stories objectAtIndex:[indexPath row]] objectForKey:@"title"]; self.detailViewController.detailSubtitle.text = [[stories objectAtIndex:[indexPath row]] objectForKey:@"subtitle"]; // this one, not so much... [self.detailViewController loadUpImageWith:imageName]; } </code></pre> <h2>and in my Detail view controller:</h2> <pre><code>- (void)loadUpImageWith:(NSString *)what { NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"strips/%@", what]]; NSLog(@"The file's url is: %@",path); UIImage *img = [UIImage imageWithContentsOfFile:path]; NSLog(@"The resultant image is: %@",img); stripImage.image = img; } </code></pre> <h2>But here's the weird thing... If I replace the variable ("what" in this case) with a string literal:</h2> <pre><code>NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"strips/%@", @"grumbles300.jpg"]]; </code></pre> <hr> <p>... it works, displaying that <strong>one</strong> image. But I want to be able to use a variable there!!</p> <p>Help me Obiwan Kenobi! You're my only hope.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload