Challenge:More Data with subclass & IB xib file


#1

UTube tutorial “Creating custom a UITableViewCell with Interface Builder” by JulioEBarros said there are 3 ways to customize the table cell.

This is the 3rd way with Interface Builder xib file.
Since I am not familiar with Xcode and Iphone pgmming, there may be a better way or bug here. Please correct if any so that I can learn.

//
// RSSItemCell.h
// Nerdfeed_b_challenge1
//
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@class RSSItem;

@interface RSSItemCell : UITableViewCell
{
IBOutlet UILabel *titleLabel;
IBOutlet UILabel *authorLabel;
IBOutlet UILabel *categoryLabel;
}

@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UILabel *authorLabel;
@property (nonatomic, retain) IBOutlet UILabel *categoryLabel;

  • (void)setItemCell:(RSSItem *)rssItem;

@end

//
// RSSItemCell.m
// Nerdfeed_b_challenge1
//
//

#import “RSSItemCell.h”
#import “RSSItem.h”

@implementation RSSItemCell
@synthesize titleLabel, authorLabel, categoryLabel;

  • (void)setItemCell:(RSSItem *)rssItem
    {
    [titleLabel setText:[rssItem title]];
    [authorLabel setText:[NSString stringWithFormat:@" by %@",[rssItem author] ]];
    [categoryLabel setText:[NSString stringWithFormat:@“Category : %@”,[rssItem category]]];
    }

@end

ListViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    RSSItemCell *cell = (RSSItemCell *)[tableView dequeueReusableCellWithIdentifier:@"RSSItemCell"];
    
    if (!cell) {
        
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RSSItemCell" owner:nil options:nil];
        for (id currentObject in topLevelObjects) {
            NSLog(@"current object = %@, class = %@", currentObject,[UITableViewCell class]);
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                cell = (RSSItemCell *)currentObject;
            }
        }
    }
    
    RSSItem *item = [[channel items] objectAtIndex:[indexPath row]];
    [cell setItemCell:item];
    
    return cell;
}


RSSItemCell.xib

  1. create empty interface and name it RSSItemCell.xib.
  2. add TableViewCell
  3. Change the owner of the TableViewCell to RSSItemCell.
  4. add 3 UILabel to the TableViewCell.
  5. connect the 3 outlets.
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="8.00">
	<data>
		<int key="IBDocument.SystemTarget">1280</int>
		<string key="IBDocument.SystemVersion">11C74</string>
		<string key="IBDocument.InterfaceBuilderVersion">1938</string>
		<string key="IBDocument.AppKitVersion">1138.23</string>
		<string key="IBDocument.HIToolboxVersion">567.00</string>
		<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
			<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
			<string key="NS.object.0">933</string>
		</object>
		<array key="IBDocument.IntegratedClassDependencies">
			<string>IBProxyObject</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="841351856">
				<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
				<string key="targetRuntimeIdentifier">IBIPadFramework</string>
			</object>
			<object class="IBProxyObject" id="371349661">
				<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
				<string key="targetRuntimeIdentifier">IBIPadFramework</string>
			</object>
			<object class="IBUITableViewCell" id="656739534">
				<reference key="NSNextResponder"/>
				<int key="NSvFlags">292</int>
				<array class="NSMutableArray" key="NSSubviews">
					<object class="IBUIView" id="700505867">
						<reference key="NSNextResponder" ref="656739534"/>
						<int key="NSvFlags">256</int>
						<array class="NSMutableArray" key="NSSubviews">
							<object class="IBUILabel" id="747164146">
								<reference key="NSNextResponder" ref="700505867"/>
								<int key="NSvFlags">292</int>
								<string key="NSFrame">{{15, 0}, {306, 21}}</string>
								<reference key="NSSuperview" ref="700505867"/>
								<reference key="NSWindow"/>
								<reference key="NSNextKeyView" ref="617126286"/>
								<string key="NSReuseIdentifierKey">_NS:345</string>
								<bool key="IBUIOpaque">NO</bool>
								<bool key="IBUIClipsSubviews">YES</bool>
								<int key="IBUIContentMode">7</int>
								<bool key="IBUIUserInteractionEnabled">NO</bool>
								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
								<string key="IBUIText">Title</string>
								<object class="NSColor" key="IBUITextColor" id="409527795">
									<int key="NSColorSpace">1</int>
									<bytes key="NSRGB">MCAwIDAAA</bytes>
								</object>
								<nil key="IBUIHighlightedColor"/>
								<int key="IBUIBaselineAdjustment">1</int>
								<float key="IBUIMinimumFontSize">10</float>
								<object class="IBUIFontDescription" key="IBUIFontDescription" id="708826019">
									<int key="type">1</int>
									<double key="pointSize">17</double>
								</object>
								<object class="NSFont" key="IBUIFont" id="413526065">
									<string key="NSName">Helvetica</string>
									<double key="NSSize">17</double>
									<int key="NSfFlags">16</int>
								</object>
							</object>
							<object class="IBUILabel" id="134942271">
								<reference key="NSNextResponder" ref="700505867"/>
								<int key="NSvFlags">292</int>
								<string key="NSFrame">{{329, 0}, {303, 21}}</string>
								<reference key="NSSuperview" ref="700505867"/>
								<reference key="NSWindow"/>
								<reference key="NSNextKeyView"/>
								<string key="NSReuseIdentifierKey">_NS:345</string>
								<bool key="IBUIOpaque">NO</bool>
								<bool key="IBUIClipsSubviews">YES</bool>
								<int key="IBUIContentMode">7</int>
								<bool key="IBUIUserInteractionEnabled">NO</bool>
								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
								<string key="IBUIText">Author</string>
								<reference key="IBUITextColor" ref="409527795"/>
								<nil key="IBUIHighlightedColor"/>
								<int key="IBUIBaselineAdjustment">1</int>
								<float key="IBUIMinimumFontSize">10</float>
								<reference key="IBUIFontDescription" ref="708826019"/>
								<reference key="IBUIFont" ref="413526065"/>
							</object>
							<object class="IBUILabel" id="617126286">
								<reference key="NSNextResponder" ref="700505867"/>
								<int key="NSvFlags">292</int>
								<string key="NSFrame">{{15, 22}, {517, 21}}</string>
								<reference key="NSSuperview" ref="700505867"/>
								<reference key="NSWindow"/>
								<reference key="NSNextKeyView" ref="134942271"/>
								<string key="NSReuseIdentifierKey">_NS:345</string>
								<bool key="IBUIOpaque">NO</bool>
								<bool key="IBUIClipsSubviews">YES</bool>
								<int key="IBUIContentMode">7</int>
								<bool key="IBUIUserInteractionEnabled">NO</bool>
								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
								<string key="IBUIText">Category</string>
								<reference key="IBUITextColor" ref="409527795"/>
								<nil key="IBUIHighlightedColor"/>
								<int key="IBUIBaselineAdjustment">1</int>
								<float key="IBUIMinimumFontSize">10</float>
								<reference key="IBUIFontDescription" ref="708826019"/>
								<reference key="IBUIFont" ref="413526065"/>
							</object>
						</array>
						<string key="NSFrameSize">{613, 43}</string>
						<reference key="NSSuperview" ref="656739534"/>
						<reference key="NSWindow"/>
						<reference key="NSNextKeyView" ref="747164146"/>
						<string key="NSReuseIdentifierKey">_NS:396</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">{613, 44}</string>
				<reference key="NSSuperview"/>
				<reference key="NSWindow"/>
				<reference key="NSNextKeyView" ref="700505867"/>
				<string key="NSReuseIdentifierKey">_NS:385</string>
				<string key="targetRuntimeIdentifier">IBIPadFramework</string>
				<reference key="IBUIContentView" ref="700505867"/>
			</object>
		</array>
		<object class="IBObjectContainer" key="IBDocument.Objects">
			<array class="NSMutableArray" key="connectionRecords">
				<object class="IBConnectionRecord">
					<object class="IBCocoaTouchOutletConnection" key="connection">
						<string key="label">categoryLabel</string>
						<reference key="source" ref="656739534"/>
						<reference key="destination" ref="617126286"/>
					</object>
					<int key="connectionID">6</int>
				</object>
				<object class="IBConnectionRecord">
					<object class="IBCocoaTouchOutletConnection" key="connection">
						<string key="label">titleLabel</string>
						<reference key="source" ref="656739534"/>
						<reference key="destination" ref="747164146"/>
					</object>
					<int key="connectionID">7</int>
				</object>
				<object class="IBConnectionRecord">
					<object class="IBCocoaTouchOutletConnection" key="connection">
						<string key="label">authorLabel</string>
						<reference key="source" ref="656739534"/>
						<reference key="destination" ref="134942271"/>
					</object>
					<int key="connectionID">8</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="841351856"/>
						<reference key="parent" ref="0"/>
						<string key="objectName">RSSItemCell</string>
					</object>
					<object class="IBObjectRecord">
						<int key="objectID">-2</int>
						<reference key="object" ref="371349661"/>
						<reference key="parent" ref="0"/>
					</object>
					<object class="IBObjectRecord">
						<int key="objectID">2</int>
						<reference key="object" ref="656739534"/>
						<array class="NSMutableArray" key="children">
							<reference ref="617126286"/>
							<reference ref="747164146"/>
							<reference ref="134942271"/>
						</array>
						<reference key="parent" ref="0"/>
					</object>
					<object class="IBObjectRecord">
						<int key="objectID">3</int>
						<reference key="object" ref="747164146"/>
						<reference key="parent" ref="656739534"/>
					</object>
					<object class="IBObjectRecord">
						<int key="objectID">4</int>
						<reference key="object" ref="134942271"/>
						<reference key="parent" ref="656739534"/>
					</object>
					<object class="IBObjectRecord">
						<int key="objectID">5</int>
						<reference key="object" ref="617126286"/>
						<reference key="parent" ref="656739534"/>
					</object>
				</array>
			</object>
			<dictionary class="NSMutableDictionary" key="flattenedProperties">
				<string key="-1.CustomClassName">RSSItemCell</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="2.CustomClassName">RSSItemCell</string>
				<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</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>
			</dictionary>
			<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
			<nil key="activeLocalization"/>
			<dictionary class="NSMutableDictionary" key="localizations"/>
			<nil key="sourceID"/>
			<int key="maxID">8</int>
		</object>
		<object class="IBClassDescriber" key="IBDocument.Classes">
			<array class="NSMutableArray" key="referencedPartialClassDescriptions">
				<object class="IBPartialClassDescription">
					<string key="className">RSSItemCell</string>
					<string key="superclassName">UITableViewCell</string>
					<dictionary class="NSMutableDictionary" key="outlets">
						<string key="authorLabel">UILabel</string>
						<string key="categoryLabel">UILabel</string>
						<string key="titleLabel">UILabel</string>
					</dictionary>
					<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
						<object class="IBToOneOutletInfo" key="authorLabel">
							<string key="name">authorLabel</string>
							<string key="candidateClassName">UILabel</string>
						</object>
						<object class="IBToOneOutletInfo" key="categoryLabel">
							<string key="name">categoryLabel</string>
							<string key="candidateClassName">UILabel</string>
						</object>
						<object class="IBToOneOutletInfo" key="titleLabel">
							<string key="name">titleLabel</string>
							<string key="candidateClassName">UILabel</string>
						</object>
					</dictionary>
					<object class="IBClassDescriptionSource" key="sourceIdentifier">
						<string key="majorKey">IBProjectSource</string>
						<string key="minorKey">./Classes/RSSItemCell.h</string>
					</object>
				</object>
			</array>
		</object>
		<int key="IBDocument.localizationMode">0</int>
		<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
		<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
		<int key="IBDocument.defaultPropertyAccessControl">3</int>
		<string key="IBCocoaTouchPluginVersion">933</string>
	</data>
</archive>