Note that there are some explanatory texts on larger screens.

plurals
  1. POConfiguring a UITableViewCell object with unique image and text
    primarykey
    data
    text
    <p>Given a <code>.plist</code> similar to :</p> <pre><code>&lt;plist version="1.0"&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;name&lt;/key&gt; &lt;string&gt;Afghanistan&lt;/string&gt; &lt;key&gt;government&lt;/key&gt; &lt;string&gt;Islamic Republic&lt;/string&gt; &lt;key&gt;population&lt;/key&gt; &lt;integer&gt;0&lt;/integer&gt; &lt;key&gt;image&lt;/key&gt; &lt;string&gt;/Flags/afghanistan.png&lt;/string&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;name&lt;/key&gt; &lt;string&gt;Albania&lt;/string&gt; &lt;key&gt;government&lt;/key&gt; &lt;string&gt;Emerging Democracy&lt;/string&gt; &lt;key&gt;population&lt;/key&gt; &lt;integer&gt;0&lt;/integer&gt; &lt;key&gt;image&lt;/key&gt; &lt;string&gt;/Flags/albania.png&lt;/string&gt; &lt;/dict&gt; .... etc. </code></pre> <p>And <strong>ViewController.m</strong> :</p> <pre><code>#import "FirstViewController.h" @implementation FirstViewController @synthesize sortedCountries; -(void)viewDidLoad { NSString *path = [[NSBundle mainBundle] pathForResource:@"countries" ofType:@"plist"]; NSArray *countries = [NSArray arrayWithContentsOfFile:path]; NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES] autorelease]; self.sortedCountries = [countries sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *country = [sortedCountries objectAtIndex:indexPath.row]; NSString *countryName = [country objectForKey:@"name"]; static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSDictionary *item = (NSDictionary *)[sortedCountries objectAtIndex:indexPath.row]; NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"image"] ofType:@"png"]; UIImage *theImage = [UIImage imageWithContentsOfFile:path]; cell.imageView.image = theImage; cell.textLabel.text = countryName; return cell; } </code></pre> <p>This puts <code>countryName</code> in ascending alphabetical order as expeted in the UITableView Cells. What is not working is <code>cell.imageView.image</code>.</p> <p>It puts afghanistan.png in the first UITableViewCell as expected. The Cells that follow also receive afghanistan.png as well however. ( The second cell should receive 'albania.png', etc ). How can I fix this UIImageView problem? </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