Graphics Programs Reference
In-Depth Information
When an instance of
ImageViewController
is created, it will be given an image.
Anytime it is displayed, it will resize its
imageView
to fit the image and tell its
scrollView
to update its content size to match. In
ImageViewController.m
,
synthesize the
image
property and implement
viewWillAppear:
to configure the
views.
@implementation ImageViewController
@synthesize image;
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGSize sz = [[self image] size];
[scrollView setContentSize:sz];
[imageView setFrame:CGRectMake(0, 0, sz.width, sz.height)];
[imageView setImage:[self image]];
}
@end
Now you can finish implementing
showImage:atIndexPath:
. First, in
Item-
sViewController.h
, declare that
ItemsViewController
conforms to
UIPop-
overControllerDelegate
and give it an instance variable to hold the popover.
@interface ItemsViewController : UITableViewController
<UIPopoverControllerDelegate>
{
UIPopoverController *imagePopover;
}
Next, import the appropriate header files at the top of
ItemsViewController.m
.
#import "BNRImageStore.h"
#import "ImageViewController.h"
Flesh out the implementation of
showImage:atIndexPath:
to present the popover
controller that displays the full-size image for the
BNRItem
represented by the cell that
was tapped.
- (void)showImage:(id)sender atIndexPath:(NSIndexPath *)ip
{
NSLog(@"Going to show the image for %@", ip);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// Get the item for the index path
BNRItem *i = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[ip row]];
NSString *imageKey = [i imageKey];
// If there is no image, we don't need to display anything
UIImage *img = [[BNRImageStore sharedStore] imageForKey:imageKey];
if (!img)