viewWillAppear pg204 use of item vs _item


#1

On page 204 the book has me overriding viewWillAppear using the item property it added to BNRDetailViewController.h. When I built it I got errors asking did I mean to use _item. _item built without errors and works.

Where did I go wrong?

Thanks,

John T. Shea

From BNRDetailViewController.h

@class BNRItem;

@interface BNRDetailViewController : UIViewController

@property (nonatomic, strong)BNRItem *item;

@end

From BNRDetailViewController.m

[code]- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear];

self.nameField.text = item.itemName;
self.serialNumberField.text = item.serialNumber;
self.valueField.text = [NSString stringWithFormat:@"%d",item.valueInDollars];

// you need a NSDateFormatter that will turn a date into a simple date string
static NSDateFormatter *dateFormatter = nil;
if (!dateFormatter) {
    dateFormatter = [[NSDateFormatter alloc]init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterNoStyle;
    
}

// use filtered NSDate object to set dateLable contents
self.dateLabel.text = [dateFormatter stringFromDate:item.dateCreated];

}

[/code]


#2

Hi mambo75,

It appears that you skipped a line:

[code]- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear];

// You missed this line
BNRItem *item = self.item;

self.nameField.text = item.itemName;

…[/code]

The authors make a local reference to _item with this line: BNRItem *item = self.item; and then use item rather than _item, but they both work the same.


#3

Yep that was it.

Thanks,

John T. Shea