1st option implementation on pg252. Is this the way?


#1

// ItemsViewController.h

#import <Foundation/Foundation.h>
#import “ItemDetailViewController.h”

@interface ItemsViewController : UITableViewController

  • (IBAction)addNewPosition:(id)sender;

- (void)reloadData;

@end

// ItemsViewController.m

- (void)reloadData
{
[[self tableView] reloadData];
}

  • (IBAction)addNewPosition:(id)sender
    {
    Possession *newPossession = [[PossessionStore defaultStore] createPossession];
    ItemDetailViewController *detailViewController = [[ItemDetailViewController alloc] initForNewItem:YES];

    [detailViewController setPossession:newPossession];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

    [detailViewController release];

    [navController setModalPresentationStyle:UIModalPresentationFormSheet];
    [navController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

[detailViewController setItemsViewController:self];

[self presentModalViewController:navController animated:YES];

[navController release];

}

// ItemDetailViewController.h

#import <UIKit/UIKit.h>

@class Possession;
@class ItemsViewController;

@interface ItemDetailViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate, UIPopoverControllerDelegate>
{
IBOutlet UITextField *nameField;
IBOutlet UITextField *serialNumberField;
IBOutlet UITextField *valueField;
IBOutlet UILabel *dateLabel;
IBOutlet UIImageView *imageView;

Possession *possession;

ItemsViewController *itemsViewController;

UIPopoverController *imagePickerPopover;

}

  • (id)initForNewItem:(BOOL)isNew;

@property (nonatomic, retain) Possession *possession;
@property (nonatomic, assign) ItemsViewController *itemsViewController;

  • (IBAction)takePicture:(id)sender;
  • (IBAction)backgroundTapped:(id)sender;

@end

//
// ItemDetailViewController.m

#import “ItemDetailViewController.h”
#import “Possession.h”
#import “ImageStore.h”
#import “PossessionStore.h”
#import “ItemsViewController.h”

@implementation ItemDetailViewController

@synthesize possession;
@synthesize itemsViewController;

  • (IBAction)save:(id)sender
    {
    [self dismissModalViewControllerAnimated:YES];
    [itemsViewController reloadData];
    }

  • (IBAction)cancel:(id)sender
    {
    [[PossessionStore defaultStore] removePossession:possession];
    [self dismissModalViewControllerAnimated:YES];
    [itemsViewController reloadData];
    }