Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using a custom cell for BNR items and persisting image data

  • Loading branch information...
commit 8dcd0e5c5633955c8d324e8bd7fe024720e058c0 1 parent 8da3f41
Ryan Blunden authored
View
10 Homepwner/Homepwner.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 4158520C025765049AC56923 /* HomePwnerItemCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 415856D6A60DCA570017E332 /* HomePwnerItemCell.m */; };
415853737489ED12DEF61B6C /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41585F6D80190DDEE6F3CC11 /* DetailViewController.m */; };
4158554A4CD30B68708AF936 /* BNRImageStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 415855D28AE7A70B489F6776 /* BNRImageStore.m */; };
41585A089C8EB584FFC175BF /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 4158582136161385D66F6958 /* Constants.m */; };
@@ -26,6 +27,7 @@
A839FD0E16A4CC920048E3BC /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A839FD0D16A4CC920048E3BC /* Default-568h@2x.png */; };
A8C22B3A16A5FF260086901C /* DeleteIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = A8C22B3816A5FF260086901C /* DeleteIcon.png */; };
A8C22B3B16A5FF260086901C /* DeleteIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A8C22B3916A5FF260086901C /* DeleteIcon@2x.png */; };
+ A8D9439016A73665005EEC04 /* HomePwnerItemCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = A8D9438F16A73665005EEC04 /* HomePwnerItemCell.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -35,8 +37,10 @@
415853BE894CF163873B73F4 /* BNRItemStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNRItemStore.h; sourceTree = "<group>"; };
415854AD59503F7C1B76969B /* BNRItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNRItem.m; sourceTree = "<group>"; };
415855D28AE7A70B489F6776 /* BNRImageStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNRImageStore.m; sourceTree = "<group>"; };
+ 415856D6A60DCA570017E332 /* HomePwnerItemCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomePwnerItemCell.m; sourceTree = "<group>"; };
415856DB55574812310903C0 /* BNRItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNRItem.h; sourceTree = "<group>"; };
415856F814FBA3B109A3C0AB /* DetailViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DetailViewController.xib; sourceTree = "<group>"; };
+ 415857EC07F9D5D86E41FE26 /* HomePwnerItemCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomePwnerItemCell.h; sourceTree = "<group>"; };
4158582136161385D66F6958 /* Constants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Constants.m; sourceTree = "<group>"; };
41585AA16B8AC169D7F7DCCE /* HeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HeaderView.xib; sourceTree = "<group>"; };
41585C2442C449CD9820748A /* ItemsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ItemsViewController.m; sourceTree = "<group>"; };
@@ -58,6 +62,7 @@
A839FD0D16A4CC920048E3BC /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
A8C22B3816A5FF260086901C /* DeleteIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = DeleteIcon.png; sourceTree = "<group>"; };
A8C22B3916A5FF260086901C /* DeleteIcon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "DeleteIcon@2x.png"; sourceTree = "<group>"; };
+ A8D9438F16A73665005EEC04 /* HomePwnerItemCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HomePwnerItemCell.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -111,6 +116,7 @@
41585C2442C449CD9820748A /* ItemsViewController.m */,
415853BA54C68788AD509DAC /* ItemsViewController.h */,
415854AD59503F7C1B76969B /* BNRItem.m */,
+ A8D9438F16A73665005EEC04 /* HomePwnerItemCell.xib */,
415856DB55574812310903C0 /* BNRItem.h */,
41585FCF8851023AD2ADAB63 /* BNRItemStore.m */,
415853BE894CF163873B73F4 /* BNRItemStore.h */,
@@ -122,6 +128,8 @@
415856F814FBA3B109A3C0AB /* DetailViewController.xib */,
415855D28AE7A70B489F6776 /* BNRImageStore.m */,
4158500D08983A6F89F91A45 /* BNRImageStore.h */,
+ 415856D6A60DCA570017E332 /* HomePwnerItemCell.m */,
+ 415857EC07F9D5D86E41FE26 /* HomePwnerItemCell.h */,
);
path = Homepwner;
sourceTree = "<group>";
@@ -209,6 +217,7 @@
41585B9F45C9DB27BD54F792 /* DetailViewController.xib in Resources */,
A8C22B3A16A5FF260086901C /* DeleteIcon.png in Resources */,
A8C22B3B16A5FF260086901C /* DeleteIcon@2x.png in Resources */,
+ A8D9439016A73665005EEC04 /* HomePwnerItemCell.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -227,6 +236,7 @@
41585A089C8EB584FFC175BF /* Constants.m in Sources */,
415853737489ED12DEF61B6C /* DetailViewController.m in Sources */,
4158554A4CD30B68708AF936 /* BNRImageStore.m in Sources */,
+ 4158520C025765049AC56923 /* HomePwnerItemCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2  Homepwner/Homepwner/BNRImageStore.m
@@ -68,7 +68,7 @@ - (UIImage *)imageForKey:(NSString *)key {
[_dictionary setObject:result forKey:key];
}
else {
- NSLog(@"Error: unable to find %@", [self imageForKey:key]);
+ NSLog(@"Error: unable to find %@", key);
}
}
View
4 Homepwner/Homepwner/BNRItem.h
@@ -19,10 +19,14 @@
@property (nonatomic, readonly, strong) NSDate *dateCreated;
@property (nonatomic, copy) NSString *imageKey;
+@property (nonatomic, strong) UIImage *thumbnail;
+@property (nonatomic, strong) NSData *thumbnailData;
+
+ (id)randomItem;
- (id)initWithItemName:(NSString *)name
valueInDollars:(int)value
serialNumber:(NSString *)sNumber;
+- (void)setThumbnailDataFromImage:(UIImage *)image;
@end
View
61 Homepwner/Homepwner/BNRItem.m
@@ -6,6 +6,7 @@
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
+#import <CoreGraphics/CoreGraphics.h>
#import "BNRItem.h"
@implementation BNRItem
@@ -69,6 +70,62 @@ - (id)initWithItemName:(NSString *)name
return self;
}
+- (UIImage *)thumbnail {
+ // If there is no thumbnail data, then I have no thumbnail to return
+ if (!_thumbnailData) {
+ return nil;
+ }
+
+ // If I have not yet created my thumbnail image from my data, do so now
+ if (!_thumbnail) {
+ // Create the image from the data
+ _thumbnail = [UIImage imageWithData:_thumbnailData];
+ }
+
+ return _thumbnail;
+}
+
+- (void)setThumbnailDataFromImage:(UIImage *)image {
+ CGSize origImageSize = [image size];
+
+ // The rectangle
+ CGRect newRect = CGRectMake(0, 0, 40, 40);
+
+ // Figure out scaling ratio to make sure we maintain the same aspect ratio
+ float ratio = MAX(newRect.size.width / origImageSize.width, newRect.size.height / origImageSize.height);
+
+ // Create a transparent bitmap context with a scaling factor equal to that of the screen
+ UIGraphicsBeginImageContextWithOptions(newRect.size, NO, 0.0);
+
+ // Create a path that is a rounded rectangle
+ UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:5.0];
+
+ // Make all subsequent drawing clip to this rounded rectangle
+ [path addClip];
+
+ // Center the image in the thumbnail rectangle
+ CGRect projectRect;
+ projectRect.size.width = ratio * origImageSize.width;
+ projectRect.size.height = ratio * origImageSize.height;
+ projectRect.origin.x = (newRect.size.width - projectRect.size.width) / 2.0;
+ projectRect.origin.y = (newRect.size.height - projectRect.size.height) / 2.0;
+
+ // Draw the image on it
+ [image drawInRect:projectRect];
+
+ // Get the image from the context, keep it as our thumbnail
+ UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
+ [self setThumbnail:smallImage];
+
+ // Get the PNG representation of the image and set it as our archivable data
+ NSData *data = UIImagePNGRepresentation(smallImage);
+ [self setThumbnailData:data];
+
+ // Cleanup image context resources, we're done
+ UIGraphicsEndImageContext();
+}
+
+
- (id)init {
return [self initWithItemName:@"Possession"
valueInDollars:0
@@ -98,6 +155,8 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:[self imageKey] forKey:@"imageKey"];
[aCoder encodeInt:[self valueInDollars] forKey:@"valueInDollars"];
+
+ [aCoder encodeObject:[self thumbnailData] forKey:@"thumbnailData"];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
@@ -110,6 +169,8 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
[self setValueInDollars:[aDecoder decodeIntForKey:@"valueInDollars"]];
dateCreated = [aDecoder decodeObjectForKey:@"dateCreated"];
+
+ _thumbnailData = [aDecoder decodeObjectForKey:@"thumbnailData"];
}
return self;
View
2  Homepwner/Homepwner/Constants.m
@@ -1,3 +1,3 @@
#import "Constants.h"
-NSString *const kItemsUITableCell = @"BNRITemTableViewCel";
+NSString *const kItemsUITableCell = @"HomePwnerItemCell";
View
2  Homepwner/Homepwner/DetailViewController.m
@@ -250,6 +250,8 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
// Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
+ [[self item] setThumbnailDataFromImage:image];
+
// Create a NSUUID object - and get its string representation
NSUUID *uuid = [[NSUUID alloc] init];
NSString *key = [uuid UUIDString];
View
19 Homepwner/Homepwner/HomePwnerItemCell.h
@@ -0,0 +1,19 @@
+//
+// Created by rblunden on 1/16/13.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface HomePwnerItemCell : UITableViewCell{
+}
+
+@property (weak, nonatomic) IBOutlet UIImageView *thumbnailView;
+@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
+@property (weak, nonatomic) IBOutlet UILabel *serialNumberLabel;
+@property (weak, nonatomic) IBOutlet UILabel *valueLabel;
+
+@end
View
67 Homepwner/Homepwner/HomePwnerItemCell.m
@@ -0,0 +1,67 @@
+//
+// Created by rblunden on 1/16/13.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import "HomePwnerItemCell.h"
+
+@implementation HomePwnerItemCell
+
+- (void)awakeFromNib {
+ for (UIView *v in [[self contentView] subviews]) {
+ [v setTranslatesAutoresizingMaskIntoConstraints:NO];
+ }
+
+ // Name all of the views for the visual format string
+ NSDictionary *names = @{
+ @"image" : [self thumbnailView],
+ @"name" : [self nameLabel],
+ @"value" : [self valueLabel],
+ @"serial" : [self serialNumberLabel]
+ };
+
+ // Create a horizontal visual format string
+ NSString *fmt = @"H:|-2-[image(==40)]-[name]-[value(==42)]-|";
+
+ // Create the constraints from this visual format string
+ NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:fmt
+ options:0
+ metrics:nil views:names];
+
+ // Add the constraints to the content view, which is the superview for all of the cell's content
+ [[self contentView] addConstraints:constraints];
+
+ fmt = @"V:|-1-[name(==20)]-(>=0)-[serial(==20)]-1-|";
+ constraints = [NSLayoutConstraint constraintsWithVisualFormat:fmt
+ options:NSLayoutFormatAlignAllLeft
+ metrics:nil
+ views:names];
+ [[self contentView] addConstraints:constraints];
+
+ NSArray * (^constraintBuilder)(UIView *, float);
+ constraintBuilder = ^(UIView *view, float height) {
+ return @[
+ // Constraint 0: Center Y of incoming view to contentView
+ [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterY
+ relatedBy:NSLayoutRelationEqual toItem:[self contentView]
+ attribute:NSLayoutAttributeCenterY multiplier:1.0
+ constant:0.0],
+
+ // Constraint 1 - Pin width of incoming view to constant height
+ [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeHeight
+ relatedBy:NSLayoutRelationEqual toItem:nil
+ attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0
+ constant:height]
+ ];
+ };
+
+ constraints = constraintBuilder([self thumbnailView] , 40);
+ [[self contentView] addConstraints:constraints];
+
+ constraints = constraintBuilder([self valueLabel], 21);
+ [[self contentView] addConstraints:constraints];
+}
+
+@end
View
322 Homepwner/Homepwner/HomePwnerItemCell.xib
@@ -0,0 +1,322 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
+ <data>
+ <int key="IBDocument.SystemTarget">1536</int>
+ <string key="IBDocument.SystemVersion">12C60</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2844</string>
+ <string key="IBDocument.AppKitVersion">1187.34</string>
+ <string key="IBDocument.HIToolboxVersion">625.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="NS.object.0">1930</string>
+ </object>
+ <array key="IBDocument.IntegratedClassDependencies">
+ <string>IBProxyObject</string>
+ <string>IBUIImageView</string>
+ <string>IBUILabel</string>
+ <string>IBUITableViewCell</string>
+ </array>
+ <array key="IBDocument.PluginDependencies">
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </array>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0"/>
+ </object>
+ <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <object class="IBProxyObject" id="372490531">
+ <string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBProxyObject" id="975951072">
+ <string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUITableViewCell" id="317265864">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">292</int>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="IBUIView" id="597451976">
+ <reference key="NSNextResponder" ref="317265864"/>
+ <int key="NSvFlags">256</int>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="IBUIImageView" id="112263179">
+ <reference key="NSNextResponder" ref="597451976"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrameSize">{39, 39}</string>
+ <reference key="NSSuperview" ref="597451976"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="889507284"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ <object class="IBUILabel" id="889507284">
+ <reference key="NSNextResponder" ref="597451976"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{42, -1}, {42, 21}}</string>
+ <reference key="NSSuperview" ref="597451976"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="532736004"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">7</int>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">Label</string>
+ <nil key="IBUITextColor"/>
+ <object class="NSColor" key="IBUIHighlightedColor" id="928457284">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ <int key="IBUIBaselineAdjustment">0</int>
+ <object class="IBUIFontDescription" key="IBUIFontDescription" id="375034239">
+ <int key="type">1</int>
+ <double key="pointSize">16</double>
+ </object>
+ <object class="NSFont" key="IBUIFont" id="646490743">
+ <string key="NSName">Helvetica</string>
+ <double key="NSSize">16</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ <bool key="IBUIAdjustsFontSizeToFit">NO</bool>
+ </object>
+ <object class="IBUILabel" id="532736004">
+ <reference key="NSNextResponder" ref="597451976"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{42, 18}, {42, 21}}</string>
+ <reference key="NSSuperview" ref="597451976"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="645608192"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">7</int>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">Label</string>
+ <object class="NSColor" key="IBUITextColor" id="568367761">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MCAwIDAAA</bytes>
+ <string key="IBUIColorCocoaTouchKeyPath">darkTextColor</string>
+ </object>
+ <reference key="IBUIHighlightedColor" ref="928457284"/>
+ <int key="IBUIBaselineAdjustment">0</int>
+ <object class="IBUIFontDescription" key="IBUIFontDescription">
+ <int key="type">1</int>
+ <double key="pointSize">13</double>
+ </object>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica</string>
+ <double key="NSSize">13</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ <bool key="IBUIAdjustsFontSizeToFit">NO</bool>
+ </object>
+ <object class="IBUILabel" id="645608192">
+ <reference key="NSNextResponder" ref="597451976"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{235, 7}, {42, 21}}</string>
+ <reference key="NSSuperview" ref="597451976"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">7</int>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">Label</string>
+ <reference key="IBUITextColor" ref="568367761"/>
+ <reference key="IBUIHighlightedColor" ref="928457284"/>
+ <int key="IBUIBaselineAdjustment">0</int>
+ <reference key="IBUIFontDescription" ref="375034239"/>
+ <reference key="IBUIFont" ref="646490743"/>
+ <bool key="IBUIAdjustsFontSizeToFit">NO</bool>
+ </object>
+ </array>
+ <string key="NSFrameSize">{283, 39}</string>
+ <reference key="NSSuperview" ref="317265864"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="112263179"/>
+ <string key="NSReuseIdentifierKey">_NS:11</string>
+ <object class="NSColor" key="IBUIBackgroundColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MCAwAA</bytes>
+ </object>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">4</int>
+ <bool key="IBUIMultipleTouchEnabled">YES</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </array>
+ <string key="NSFrameSize">{283, 40}</string>
+ <reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="597451976"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <reference key="IBUIContentView" ref="597451976"/>
+ <real value="40" key="IBUIRowHeight"/>
+ </object>
+ </array>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <array class="NSMutableArray" key="connectionRecords">
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">nameLabel</string>
+ <reference key="source" ref="317265864"/>
+ <reference key="destination" ref="889507284"/>
+ </object>
+ <int key="connectionID">17</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">serialNumberLabel</string>
+ <reference key="source" ref="317265864"/>
+ <reference key="destination" ref="532736004"/>
+ </object>
+ <int key="connectionID">18</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">thumbnailView</string>
+ <reference key="source" ref="317265864"/>
+ <reference key="destination" ref="112263179"/>
+ </object>
+ <int key="connectionID">19</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">valueLabel</string>
+ <reference key="source" ref="317265864"/>
+ <reference key="destination" ref="645608192"/>
+ </object>
+ <int key="connectionID">20</int>
+ </object>
+ </array>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <array key="orderedObjects">
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <array key="object" id="0"/>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="372490531"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="975951072"/>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">3</int>
+ <reference key="object" ref="317265864"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="112263179"/>
+ <reference ref="889507284"/>
+ <reference ref="645608192"/>
+ <reference ref="532736004"/>
+ </array>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">4</int>
+ <reference key="object" ref="112263179"/>
+ <reference key="parent" ref="317265864"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">5</int>
+ <reference key="object" ref="889507284"/>
+ <reference key="parent" ref="317265864"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">6</int>
+ <reference key="object" ref="532736004"/>
+ <reference key="parent" ref="317265864"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">7</int>
+ <reference key="object" ref="645608192"/>
+ <reference key="parent" ref="317265864"/>
+ </object>
+ </array>
+ </object>
+ <dictionary class="NSMutableDictionary" key="flattenedProperties">
+ <string key="-1.CustomClassName">HomePwnerItemCell</string>
+ <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="-2.CustomClassName">UIResponder</string>
+ <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="3.CustomClassName">HomePwnerItemCell</string>
+ <string key="3.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <object class="NSMutableAttributedString" key="5.notes">
+ <object class="NSMutableString" key="NSString">
+ <characters key="NS.bytes"/>
+ </object>
+ </object>
+ <string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <object class="NSMutableAttributedString" key="6.notes">
+ <object class="NSMutableString" key="NSString">
+ <characters key="NS.bytes"/>
+ </object>
+ </object>
+ <string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
+ <nil key="activeLocalization"/>
+ <dictionary class="NSMutableDictionary" key="localizations"/>
+ <nil key="sourceID"/>
+ <int key="maxID">20</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">HomePwnerItemCell</string>
+ <string key="superclassName">UITableViewCell</string>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="nameLabel">UILabel</string>
+ <string key="serialNumberLabel">UILabel</string>
+ <string key="thumbnailView">UIImageView</string>
+ <string key="valueLabel">UILabel</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="nameLabel">
+ <string key="name">nameLabel</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="serialNumberLabel">
+ <string key="name">serialNumberLabel</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="thumbnailView">
+ <string key="name">thumbnailView</string>
+ <string key="candidateClassName">UIImageView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="valueLabel">
+ <string key="name">valueLabel</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/HomePwnerItemCell.h</string>
+ </object>
+ </object>
+ </array>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ <string key="IBCocoaTouchPluginVersion">1930</string>
+ </data>
+</archive>
View
36 Homepwner/Homepwner/ItemsViewController.m
@@ -9,6 +9,8 @@
#import "BNRItemStore.h"
#import "BNRItem.h"
#import "DetailViewController.h"
+#import "HomePwnerItemCell.h"
+#import "Constants.h"
@interface ItemsViewController ()
@@ -49,21 +51,20 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- // Check for a reusable cell first, use that if it exists
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kItemsUITableCell];
+ // Set the text on the cell with the description of the item
+ // that is at the nth index of items, where n = row this cell
+ // will appear in on the table view
+ BNRItem *item = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
- // If there is no reusable cell fo this type, create a new one
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kItemsUITableCell];
- }
+ // Get the new or recycled cell
+ HomePwnerItemCell *cell = [tableView dequeueReusableCellWithIdentifier:kItemsUITableCell];
+ // Configure the cell with the BNRItem
+ [[cell nameLabel] setText:[item itemName]];
+ [[cell serialNumberLabel] setText:[item serialNumber]];
+ [[cell valueLabel] setText:[NSString stringWithFormat:@"$%d", [item valueInDollars]]];
- // Set the text on the cell with the description of the item
- // that is at the nth index of items, where n = row this cell
- // will appear in on the tableview
- NSArray *items = [[BNRItemStore sharedStore] allItems];
- BNRItem *p = [items objectAtIndex:[indexPath row]];
- [[cell textLabel] setText:[p description]];
+ [[cell thumbnailView] setImage:[item thumbnail]];
return cell;
@@ -120,6 +121,17 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[[self navigationController] pushViewController:detailViewController animated:YES];
}
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ // Load the nib
+ UINib *nib = [UINib nibWithNibName:kItemsUITableCell bundle:nil];
+
+ // Register this NIB which contains the cell
+ [[self tableView] registerNib:nib forCellReuseIdentifier:kItemsUITableCell];
+
+}
+
- (void)viewDidAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self tableView] reloadData];
Please sign in to comment.
Something went wrong with that request. Please try again.