SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
Code Listings


This appendix contains code listings for the interface and implementation files of the BirdWatching project.
The listings do not include comments or methods that you do not edit.




Model Layer Files
This section contains listings for the following files:
 ●    BirdSighting.h
 ●    BirdSighting.m
 ●    BirdSightingDataController.h
 ●    BirdSightingDataController.m



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



     @interface BirdSighting : NSObject

     @property (nonatomic, copy) NSString *name;

     @property (nonatomic, copy) NSString *location;

     @property (nonatomic, strong) NSDate *date;

     -(id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate
     *)date;

     @end




BirdSighting.m
     #import "BirdSighting.h"



     @implementation BirdSighting




                                      2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                              90
Code Listings
Model Layer Files




  -(id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate
  *)date

  {

        self = [super init];

        if (self) {

              _name = name;

              _location = location;

              _date = date;

              return self;

        }

        return nil;
  }

  @end




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

  @class BirdSighting;

  @interface BirdSightingDataController : NSObject

  @property (nonatomic, copy) NSMutableArray *masterBirdSightingList;

  - (NSUInteger)countOfList;

  - (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex;

  - (void)addBirdSightingWithSighting:(BirdSighting *)sighting;

  @end




BirdSightingDataController.m
  #import "BirdSightingDataController.h"

  #import "BirdSighting.h"

  @interface BirdSightingDataController ()

  - (void)initializeDefaultDataList;

  @end

  @implementation BirdSightingDataController

  - (void)initializeDefaultDataList {

        NSMutableArray *sightingList = [[NSMutableArray alloc] init];




                                 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                         91
Code Listings
Master View Controller Files




          self.masterBirdSightingList = sightingList;

          BirdSighting *sighting;

          NSDate *today = [NSDate date];

        sighting = [[BirdSighting alloc] initWithName:@"Pigeon" location:@"Everywhere"
     date:today];

          [self addBirdSightingWithSighting:sighting];

     }

     - (void)setMasterBirdSightingList:(NSMutableArray *)newList {

          if (_masterBirdSightingList != newList) {

              _masterBirdSightingList = [newList mutableCopy];

          }
     }

     - (id)init {

          if (self = [super init]) {

              [self initializeDefaultDataList];

              return self;

          }

          return nil;

     }

     - (NSUInteger)countOfList {

          return [self.masterBirdSightingList count];

     }

     - (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex {

          return [self.masterBirdSightingList objectAtIndex:theIndex];
     }

     - (void)addBirdSightingWithSighting:(BirdSighting *)sighting {

          [self.masterBirdSightingList addObject:sighting];

     }

     @end




Master View Controller Files
This section contains listings for the following files:
 ●       BirdsMasterViewController.h



                                      2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                              92
Code Listings
Master View Controller Files



 ●       BirdsMasterViewController.m



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

     @class BirdSightingDataController;

     @interface BirdsMasterViewController : UITableViewController

     @property (strong, nonatomic) BirdSightingDataController *dataController;

     - (IBAction)done:(UIStoryboardSegue *)segue;

     - (IBAction)cancel:(UIStoryboardSegue *)segue;

     @end




BirdsMasterViewController.m
     #import "BirdsMasterViewController.h"



     #import "BirdsDetailViewController.h"

     #import "BirdSightingDataController.h"

     #import "BirdSighting.h"

     #import "AddSightingViewController.h"



     @implementation BirdsMasterViewController



     - (void)awakeFromNib
     {

          [super awakeFromNib];

          self.dataController = [[BirdSightingDataController alloc] init];

     }



     - (void)viewDidLoad

     {

          [super viewDidLoad];

         self.navigationItem.rightBarButtonItem.accessibilityHint = @"Adds a new bird
     sighting event";

          // Do any additional setup after loading the view, typically from a nib.

     }




                                  2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                          93
Code Listings
Master View Controller Files




  - (void)didReceiveMemoryWarning

  {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

  }



  #pragma mark - Table View



  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {

        return 1;

  }



  - (NSInteger)tableView:(UITableView *)tableView
  numberOfRowsInSection:(NSInteger)section {

        return [self.dataController countOfList];

  }



  - (UITableViewCell *)tableView:(UITableView *)tableView
  cellForRowAtIndexPath:(NSIndexPath *)indexPath {



        static NSString *CellIdentifier = @"BirdSightingCell";


        static NSDateFormatter *formatter = nil;

        if (formatter == nil) {

              formatter = [[NSDateFormatter alloc] init];

              [formatter setDateStyle:NSDateFormatterMediumStyle];

        }

      UITableViewCell *cell = [tableView
  dequeueReusableCellWithIdentifier:CellIdentifier];



      BirdSighting *sightingAtIndex = [self.dataController
  objectInListAtIndex:indexPath.row];

        [[cell textLabel] setText:sightingAtIndex.name];




                                  2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                          94
Code Listings
Master View Controller Files




      [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate
  *)sightingAtIndex.date]];

        return cell;

  }



  - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath
  *)indexPath

  {

        // Return NO if you do not want the specified item to be editable.

        return NO;

  }


  - (IBAction)done:(UIStoryboardSegue *)segue

  {

        if ([[segue identifier] isEqualToString:@"ReturnInput"]) {



              AddSightingViewController *addController = [segue sourceViewController];

              if (addController.birdSighting) {

              [self.dataController
  addBirdSightingWithSighting:addController.birdSighting];

                    [[self tableView] reloadData];

              }

              [self dismissViewControllerAnimated:YES completion:NULL];

        }

  }
  - (IBAction)cancel:(UIStoryboardSegue *)segue

  {

        if ([[segue identifier] isEqualToString:@"CancelInput"]) {

              [self dismissViewControllerAnimated:YES completion:NULL];

        }

  }



  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

        if ([[segue identifier] isEqualToString:@"ShowSightingDetails"]) {

          BirdsDetailViewController *detailViewController = [segue
  destinationViewController];




                                   2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                           95
Code Listings
Detail View Controller Files




             detailViewController.sighting = [self.dataController
     objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];

          }

     }



     @end




Detail View Controller Files
This section contains listings for the following files:
 ●       BirdsDetailViewController.h
 ●       BirdsDetailViewController.m



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

     @class BirdSighting;

     @interface BirdsDetailViewController : UITableViewController



     @property (strong, nonatomic) BirdSighting *sighting;

     @property (weak, nonatomic) IBOutlet UILabel *birdNameLabel;

     @property (weak, nonatomic) IBOutlet UILabel *locationLabel;

     @property (weak, nonatomic) IBOutlet UILabel *dateLabel;
     @end




BirdsDetailViewController.m
     #import "BirdsDetailViewController.h"

     #import "BirdSighting.h"

     @interface BirdsDetailViewController ()

     - (void)configureView;

     @end




                                      2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                              96
Code Listings
Detail View Controller Files




  @implementation BirdsDetailViewController



  #pragma mark - Managing the detail item



  - (void)setSighting:(BirdSighting *) newSighting

  {

        if (_sighting != newSighting) {

              _sighting = newSighting;



              // Update the view.
              [self configureView];

        }

  }



  - (void)configureView

  {

        // Update the user interface for the detail item.

        BirdSighting *theSighting = self.sighting;



        static NSDateFormatter *formatter = nil;

        if (formatter == nil) {

              formatter = [[NSDateFormatter alloc] init];

              [formatter setDateStyle:NSDateFormatterMediumStyle];
        }

        if (theSighting) {

              self.birdNameLabel.text = theSighting.name;

              self.locationLabel.text = theSighting.location;

             self.dateLabel.text = [formatter stringFromDate:(NSDate *)theSighting.date];

        }

  }



  - (void)viewDidLoad

  {

        [super viewDidLoad];




                                    2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                            97
Code Listings
Add Scene View Controller Files




          // Do any additional setup after loading the view, typically from a nib.

          [self configureView];

     }

     @end




Add Scene View Controller Files
This section contains listings for the following files:
 ●       AddSightingViewController.h
 ●       AddSightingViewController.m



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

     @class BirdSighting;

     @interface AddSightingViewController : UITableViewController <UITextFieldDelegate>

     @property (weak, nonatomic) IBOutlet UITextField *birdNameInput;

     @property (weak, nonatomic) IBOutlet UITextField *locationInput;

     @property (strong, nonatomic) BirdSighting *birdSighting;

     @end




AddSightingViewController.m
     #import "AddSightingViewController.h"

     #import "BirdSighting.h"

     @interface AddSightingViewController ()



     @end



     @implementation AddSightingViewController

     - (BOOL)textFieldShouldReturn:(UITextField *)textField {

          if ((textField == self.birdNameInput) || (textField == self.locationInput)) {

              [textField resignFirstResponder];




                                      2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                              98
Code Listings
Add Scene View Controller Files




        }

        return YES;

  }

  - (void)viewDidLoad

  {

        [super viewDidLoad];



        // Uncomment the following line to preserve selection between presentations.

        // self.clearsSelectionOnViewWillAppear = NO;



      // Uncomment the following line to display an Edit button in the navigation
  bar for this view controller.

        // self.navigationItem.rightBarButtonItem = self.editButtonItem;

  }



  - (void)didReceiveMemoryWarning

  {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

  }



  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

        if ([[segue identifier] isEqualToString:@"ReturnInput"]) {

             if ([self.birdNameInput.text length] || [self.locationInput.text length])
   {
                   BirdSighting *sighting;

                   NSDate *today = [NSDate date];

              sighting = [[BirdSighting alloc] initWithName:self.birdNameInput.text
   location:self.locationInput.text date:today];

                   self.birdSighting = sighting;

             }

        }

  }

  @end




                                  2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved.

                                                          99

Contenu connexe

Tendances

Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii명철 강
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011camp_drupal_ua
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriverchristkv
 
dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Wilson Su
 
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーSatoshi Asano
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingSamuel ROZE
 
Impact of the New ORM on Your Modules
Impact of the New ORM on Your ModulesImpact of the New ORM on Your Modules
Impact of the New ORM on Your ModulesOdoo
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&TricksPetr Bela
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 

Tendances (20)

Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
 
dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus Catalogue 2015
dcs plus Catalogue 2015
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
 
ARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマーARCでめちゃモテiOSプログラマー
ARCでめちゃモテiOSプログラマー
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
Impact of the New ORM on Your Modules
Impact of the New ORM on Your ModulesImpact of the New ORM on Your Modules
Impact of the New ORM on Your Modules
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&Tricks
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 

Similaire à Code Listings for BirdWatching Project Models and Controllers

Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III) Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III) Mobivery
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCAWhymca
 
Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.UA Mobile
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design PatternsGodfrey Nolan
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the AirAvitoTech
 
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...Mail.ru Group
 
10 tips for a reusable architecture
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architectureJorge Ortiz
 
Apple Templates Considered Harmful
Apple Templates Considered HarmfulApple Templates Considered Harmful
Apple Templates Considered HarmfulBrian Gesiak
 
303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Code303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Codejonmarimba
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Sarp Erdag
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationAbdul Malik Ikhsan
 
MBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&CoMBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&Coe-Legion
 
Net conf BG xamarin lecture
Net conf BG xamarin lectureNet conf BG xamarin lecture
Net conf BG xamarin lectureTsvyatko Konov
 
iOS Beginners Lesson 4
iOS Beginners Lesson 4iOS Beginners Lesson 4
iOS Beginners Lesson 4Calvin Cheng
 
정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리태준 김
 
I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)Katsumi Kishikawa
 
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and SimpleDrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and SimpleAlexander Varwijk
 

Similaire à Code Listings for BirdWatching Project Models and Controllers (20)

Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III) Formacion en movilidad: Conceptos de desarrollo en iOS (III)
Formacion en movilidad: Conceptos de desarrollo en iOS (III)
 
iOS
iOSiOS
iOS
 
Beginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCABeginning icloud development - Cesare Rocchi - WhyMCA
Beginning icloud development - Cesare Rocchi - WhyMCA
 
Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.Taking Objective-C to the next level. UA Mobile 2016.
Taking Objective-C to the next level. UA Mobile 2016.
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
I os 11
I os 11I os 11
I os 11
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
 
I os 04
I os 04I os 04
I os 04
 
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
 
10 tips for a reusable architecture
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architecture
 
Apple Templates Considered Harmful
Apple Templates Considered HarmfulApple Templates Considered Harmful
Apple Templates Considered Harmful
 
303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Code303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Code
 
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
 
MBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&CoMBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&Co
 
Net conf BG xamarin lecture
Net conf BG xamarin lectureNet conf BG xamarin lecture
Net conf BG xamarin lecture
 
iOS Beginners Lesson 4
iOS Beginners Lesson 4iOS Beginners Lesson 4
iOS Beginners Lesson 4
 
정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리
 
I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)
 
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and SimpleDrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
 

Plus de Vu Tran Lam

Session 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barSession 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barVu Tran Lam
 
Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Vu Tran Lam
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search barVu Tran Lam
 
Session 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 applicationSession 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 applicationVu Tran Lam
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationVu Tran Lam
 
Session 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architectureSession 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architectureVu Tran Lam
 
Session 5 - Foundation framework
Session 5 - Foundation frameworkSession 5 - Foundation framework
Session 5 - Foundation frameworkVu Tran Lam
 
Session 4 - Object oriented programming with Objective-C (part 2)
Session 4  - Object oriented programming with Objective-C (part 2)Session 4  - Object oriented programming with Objective-C (part 2)
Session 4 - Object oriented programming with Objective-C (part 2)Vu Tran Lam
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basicsVu Tran Lam
 
Session 16 - Designing universal interface which used for iPad and iPhone
Session 16  -  Designing universal interface which used for iPad and iPhoneSession 16  -  Designing universal interface which used for iPad and iPhone
Session 16 - Designing universal interface which used for iPad and iPhoneVu Tran Lam
 
iOS 7 Application Development Course
iOS 7 Application Development CourseiOS 7 Application Development Course
iOS 7 Application Development CourseVu Tran Lam
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web ViewVu Tran Lam
 
Session 1 - Introduction to iOS 7 and SDK
Session 1 -  Introduction to iOS 7 and SDKSession 1 -  Introduction to iOS 7 and SDK
Session 1 - Introduction to iOS 7 and SDKVu Tran Lam
 
Succeed in Mobile career
Succeed in Mobile careerSucceed in Mobile career
Succeed in Mobile careerVu Tran Lam
 
Android Application Development Course
Android Application Development Course Android Application Development Course
Android Application Development Course Vu Tran Lam
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentVu Tran Lam
 
Building a Completed iPhone App
Building a Completed iPhone AppBuilding a Completed iPhone App
Building a Completed iPhone AppVu Tran Lam
 
Introduction to iPhone Programming
Introduction to iPhone Programming Introduction to iPhone Programming
Introduction to iPhone Programming Vu Tran Lam
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignVu Tran Lam
 

Plus de Vu Tran Lam (20)

Session 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab barSession 13 - Working with navigation and tab bar
Session 13 - Working with navigation and tab bar
 
Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures Session 12 - Overview of taps, multitouch, and gestures
Session 12 - Overview of taps, multitouch, and gestures
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search bar
 
Session 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 applicationSession 9-10 - UI/UX design for iOS 7 application
Session 9-10 - UI/UX design for iOS 7 application
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 application
 
Session 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architectureSession 7 - Overview of the iOS7 app development architecture
Session 7 - Overview of the iOS7 app development architecture
 
Session 5 - Foundation framework
Session 5 - Foundation frameworkSession 5 - Foundation framework
Session 5 - Foundation framework
 
Session 4 - Object oriented programming with Objective-C (part 2)
Session 4  - Object oriented programming with Objective-C (part 2)Session 4  - Object oriented programming with Objective-C (part 2)
Session 4 - Object oriented programming with Objective-C (part 2)
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basics
 
Session 16 - Designing universal interface which used for iPad and iPhone
Session 16  -  Designing universal interface which used for iPad and iPhoneSession 16  -  Designing universal interface which used for iPad and iPhone
Session 16 - Designing universal interface which used for iPad and iPhone
 
iOS 7 Application Development Course
iOS 7 Application Development CourseiOS 7 Application Development Course
iOS 7 Application Development Course
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
 
Session 1 - Introduction to iOS 7 and SDK
Session 1 -  Introduction to iOS 7 and SDKSession 1 -  Introduction to iOS 7 and SDK
Session 1 - Introduction to iOS 7 and SDK
 
Succeed in Mobile career
Succeed in Mobile careerSucceed in Mobile career
Succeed in Mobile career
 
Android Application Development Course
Android Application Development Course Android Application Development Course
Android Application Development Course
 
Introduction to MVC in iPhone Development
Introduction to MVC in iPhone DevelopmentIntroduction to MVC in iPhone Development
Introduction to MVC in iPhone Development
 
Building a Completed iPhone App
Building a Completed iPhone AppBuilding a Completed iPhone App
Building a Completed iPhone App
 
Introduction to iPhone Programming
Introduction to iPhone Programming Introduction to iPhone Programming
Introduction to iPhone Programming
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 

Dernier

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Dernier (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Code Listings for BirdWatching Project Models and Controllers

  • 1. Code Listings This appendix contains code listings for the interface and implementation files of the BirdWatching project. The listings do not include comments or methods that you do not edit. Model Layer Files This section contains listings for the following files: ● BirdSighting.h ● BirdSighting.m ● BirdSightingDataController.h ● BirdSightingDataController.m BirdSighting.h #import <Foundation/Foundation.h> @interface BirdSighting : NSObject @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *location; @property (nonatomic, strong) NSDate *date; -(id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate *)date; @end BirdSighting.m #import "BirdSighting.h" @implementation BirdSighting 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 90
  • 2. Code Listings Model Layer Files -(id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate *)date { self = [super init]; if (self) { _name = name; _location = location; _date = date; return self; } return nil; } @end BirdSightingDataController.h #import <Foundation/Foundation.h> @class BirdSighting; @interface BirdSightingDataController : NSObject @property (nonatomic, copy) NSMutableArray *masterBirdSightingList; - (NSUInteger)countOfList; - (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex; - (void)addBirdSightingWithSighting:(BirdSighting *)sighting; @end BirdSightingDataController.m #import "BirdSightingDataController.h" #import "BirdSighting.h" @interface BirdSightingDataController () - (void)initializeDefaultDataList; @end @implementation BirdSightingDataController - (void)initializeDefaultDataList { NSMutableArray *sightingList = [[NSMutableArray alloc] init]; 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 91
  • 3. Code Listings Master View Controller Files self.masterBirdSightingList = sightingList; BirdSighting *sighting; NSDate *today = [NSDate date]; sighting = [[BirdSighting alloc] initWithName:@"Pigeon" location:@"Everywhere" date:today]; [self addBirdSightingWithSighting:sighting]; } - (void)setMasterBirdSightingList:(NSMutableArray *)newList { if (_masterBirdSightingList != newList) { _masterBirdSightingList = [newList mutableCopy]; } } - (id)init { if (self = [super init]) { [self initializeDefaultDataList]; return self; } return nil; } - (NSUInteger)countOfList { return [self.masterBirdSightingList count]; } - (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex { return [self.masterBirdSightingList objectAtIndex:theIndex]; } - (void)addBirdSightingWithSighting:(BirdSighting *)sighting { [self.masterBirdSightingList addObject:sighting]; } @end Master View Controller Files This section contains listings for the following files: ● BirdsMasterViewController.h 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 92
  • 4. Code Listings Master View Controller Files ● BirdsMasterViewController.m BirdsMasterViewController.h #import <UIKit/UIKit.h> @class BirdSightingDataController; @interface BirdsMasterViewController : UITableViewController @property (strong, nonatomic) BirdSightingDataController *dataController; - (IBAction)done:(UIStoryboardSegue *)segue; - (IBAction)cancel:(UIStoryboardSegue *)segue; @end BirdsMasterViewController.m #import "BirdsMasterViewController.h" #import "BirdsDetailViewController.h" #import "BirdSightingDataController.h" #import "BirdSighting.h" #import "AddSightingViewController.h" @implementation BirdsMasterViewController - (void)awakeFromNib { [super awakeFromNib]; self.dataController = [[BirdSightingDataController alloc] init]; } - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.rightBarButtonItem.accessibilityHint = @"Adds a new bird sighting event"; // Do any additional setup after loading the view, typically from a nib. } 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 93
  • 5. Code Listings Master View Controller Files - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table View - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.dataController countOfList]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"BirdSightingCell"; static NSDateFormatter *formatter = nil; if (formatter == nil) { formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row]; [[cell textLabel] setText:sightingAtIndex.name]; 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 94
  • 6. Code Listings Master View Controller Files [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return NO; } - (IBAction)done:(UIStoryboardSegue *)segue { if ([[segue identifier] isEqualToString:@"ReturnInput"]) { AddSightingViewController *addController = [segue sourceViewController]; if (addController.birdSighting) { [self.dataController addBirdSightingWithSighting:addController.birdSighting]; [[self tableView] reloadData]; } [self dismissViewControllerAnimated:YES completion:NULL]; } } - (IBAction)cancel:(UIStoryboardSegue *)segue { if ([[segue identifier] isEqualToString:@"CancelInput"]) { [self dismissViewControllerAnimated:YES completion:NULL]; } } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"ShowSightingDetails"]) { BirdsDetailViewController *detailViewController = [segue destinationViewController]; 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 95
  • 7. Code Listings Detail View Controller Files detailViewController.sighting = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row]; } } @end Detail View Controller Files This section contains listings for the following files: ● BirdsDetailViewController.h ● BirdsDetailViewController.m BirdsDetailViewController.h #import <UIKit/UIKit.h> @class BirdSighting; @interface BirdsDetailViewController : UITableViewController @property (strong, nonatomic) BirdSighting *sighting; @property (weak, nonatomic) IBOutlet UILabel *birdNameLabel; @property (weak, nonatomic) IBOutlet UILabel *locationLabel; @property (weak, nonatomic) IBOutlet UILabel *dateLabel; @end BirdsDetailViewController.m #import "BirdsDetailViewController.h" #import "BirdSighting.h" @interface BirdsDetailViewController () - (void)configureView; @end 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 96
  • 8. Code Listings Detail View Controller Files @implementation BirdsDetailViewController #pragma mark - Managing the detail item - (void)setSighting:(BirdSighting *) newSighting { if (_sighting != newSighting) { _sighting = newSighting; // Update the view. [self configureView]; } } - (void)configureView { // Update the user interface for the detail item. BirdSighting *theSighting = self.sighting; static NSDateFormatter *formatter = nil; if (formatter == nil) { formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; } if (theSighting) { self.birdNameLabel.text = theSighting.name; self.locationLabel.text = theSighting.location; self.dateLabel.text = [formatter stringFromDate:(NSDate *)theSighting.date]; } } - (void)viewDidLoad { [super viewDidLoad]; 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 97
  • 9. Code Listings Add Scene View Controller Files // Do any additional setup after loading the view, typically from a nib. [self configureView]; } @end Add Scene View Controller Files This section contains listings for the following files: ● AddSightingViewController.h ● AddSightingViewController.m AddSightingViewController.h #import <UIKit/UIKit.h> @class BirdSighting; @interface AddSightingViewController : UITableViewController <UITextFieldDelegate> @property (weak, nonatomic) IBOutlet UITextField *birdNameInput; @property (weak, nonatomic) IBOutlet UITextField *locationInput; @property (strong, nonatomic) BirdSighting *birdSighting; @end AddSightingViewController.m #import "AddSightingViewController.h" #import "BirdSighting.h" @interface AddSightingViewController () @end @implementation AddSightingViewController - (BOOL)textFieldShouldReturn:(UITextField *)textField { if ((textField == self.birdNameInput) || (textField == self.locationInput)) { [textField resignFirstResponder]; 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 98
  • 10. Code Listings Add Scene View Controller Files } return YES; } - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"ReturnInput"]) { if ([self.birdNameInput.text length] || [self.locationInput.text length]) { BirdSighting *sighting; NSDate *today = [NSDate date]; sighting = [[BirdSighting alloc] initWithName:self.birdNameInput.text location:self.locationInput.text date:today]; self.birdSighting = sighting; } } } @end 2012-‐10-‐16 | © 2012 Apple Inc. All Rights Reserved. 99