Gold Challenge Complete


#1

Here’s my solution. It’s pretty self-explanatory. hope this helps!

BNRImageViewController.m


#import "BNRImageViewController.h"

//*ADDED
@interface BNRImageViewController ()<UIScrollViewDelegate>

//*ADDED
@property(nonatomic, strong)UIImageView *imageView;


@end

@implementation BNRImageViewController

//*ADDED
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)ScrollView{

    return self.imageView;

}
//*ADDED
-(void)loadView{

    UIScrollView *scrollView = [[UIScrollView alloc]init];
    
    
    self.imageView =[[UIImageView alloc]initWithImage:self.image];
    
   
    self.imageView.contentMode = UIViewContentModeCenter;
   
    //Center the image in the popover
    [self.imageView setCenter:CGPointMake(600/2,600/2)];
    
    scrollView.contentSize = self.imageView.frame.size;
    
    scrollView.scrollEnabled = NO;
    scrollView.minimumZoomScale = 0.5;
    scrollView.maximumZoomScale = 2.0;
    scrollView.delegate = self;
 
    [scrollView addSubview:self.imageView];
    
    self.view = scrollView;
    
    
    
}

//*CHANGED
//NOTE: Must comment out or delete the two statements below
//in order for it work
-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear];
    
    //We must cast the view to UIImageView so the compiler know
    //it is okay to send it setImage:
    
    //UIImageView *imageView = (UIImageView *)self.view;
   // imageView.image = self.image;

}
@end

#2

Can you explain why you have to comment out the code in viewDidLoad? I’m a bit confused as to why we even has to cast it in the first place, and why you ended up taking it out.