Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Implementing Designs for iPhone Customizing Table View Controllers Customizing Table View Cell Disclosure Indicators

Lei zheng
Lei zheng
7,990 Points

Next we need a UIImageView to display the pizza slice UIImage. Create a UIImageView variable and set its 'image' propert

I can not figure out how this is done.

MenuViewController.m
#import "MenuViewController.h"

@implementation MenuViewController

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

    // ... some code omitted for brevity ...
    UIImage *img=[UIImage imageNamed:@"pizza_slice"];]
UIImageView *imageView=[[UIImageView alloc] initWihtImage:img];

    return cell;
}

@end

3 Answers

Sorry, I just now noticed the code challenge. :)

First task:

UIImage *img = [UIImage imageNamed:@"pizza_slice"];

Second task:

UIImageView *imageView = [[UIImageView alloc] initWithImage:img];

Third task:

cell.accessoryView = imageView;

Your solution contains two errors:

  1. You don't need the final square brackets.
UIImage *img=[UIImage imageNamed:@"pizza_slice"];**]**
  1. ht --> th
UIImageView *imageView=[[UIImageView alloc] initWi**ht**Image:img];
Chris Shaw
Chris Shaw
26,676 Points

Hi Lei,

You're very close, instead of using the constructor the challenge is asking for you to use the property called image which you can access via the variable imageView that you've created, the end result you should have is.

UIImage *img = [UIImage imageNamed:@"pizza_slice"];
UIImageView *imageView = [UIImageView alloc];
imageView.image = img;

Happy coding and Merry Christmas.

Hi Lei,

You can do this:

UIImage *img = [UIImage imageNamed:@"pizza_slice"];
cell.imageView.image = img;

or this:

UIImage *img = [UIImage imageNamed:@"pizza_slice"];]
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
[cell addSubview:imageView];

or if you need to a custom disclosure indicator:

UIImage *img = [UIImage imageNamed:@"pizza_slice"];
CGFloat cellHeight = CGRectGetHeight(cell.frame);

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cellHeight, cellHeight)];
imageView.image = img;

cell.accessoryView = imageView;

Merry Christmas! :)