Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Dávid Szép
Dávid Szép
6,125 Points

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,650 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.

Dávid Szép
Dávid Szép
6,125 Points

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! :)