Graphics Programs Reference
In-Depth Information
Now that BNRItem s have a thumbnail, you can use this thumbnail in ItemsViewCon-
troller 's table view. In ItemsViewController.m , update
tableView:cellForRowAtIndexPath: .
[[cell valueLabel] setText:
[NSString stringWithFormat:@"$%d", [p valueInDollars]]];
[[cell thumbnailView] setImage:[p thumbnail]];
return cell;
}
Now build and run the application. Take a picture for a BNRItem instance and return to
the table view. That row will display a thumbnail image along with the name and value of
the BNRItem . (Note that you will have to retake pictures for existing BNRItem s.)
Don't forget to add the thumbnail data to your archive! Open BNRItem.m :
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
[self setItemName:[aDecoder decodeObjectForKey:@"itemName"]];
[self setSerialNumber:[aDecoder decodeObjectForKey:@"serialNumber"]];
[self setImageKey:[aDecoder decodeObjectForKey:@"imageKey"]];
[self setValueInDollars:[aDecoder decodeIntForKey:@"valueInDollars"]];
dateCreated = [aDecoder decodeObjectForKey:@"dateCreated"];
thumbnailData = [aDecoder decodeObjectForKey:@"thumbnailData"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:itemName forKey:@"itemName"];
[aCoder encodeObject:serialNumber forKey:@"serialNumber"];
[aCoder encodeObject:dateCreated forKey:@"dateCreated"];
[aCoder encodeObject:imageKey forKey:@"imageKey"];
[aCoder encodeInt:valueInDollars forKey:@"valueInDollars"];
[aCoder encodeObject:thumbnailData forKey:@"thumbnailData"];
}
Build and run the application. Take some photos of items and then exit and relaunch the
application. The thumbnails will now appear for saved item objects.
Search WWH ::




Custom Search