Product Inventory App

  1. Create an Xcode project called ProductInvApp. Use the single-view template.
  2. Add three buttons onto the view representing three different products.
  3. Embed this single view in a Navigation-Controller.
  4. Add another view controller onto the story board.
  5. In that second view controller, add two labels (to display product name and stock level), two buttons (to cause increase or decrease of stock), a text field (to indicate quantity to be added or removed), and a UIImageView (to display the image of the product).
  6. Add segues for each of the buttons on the first view, all leading to the second view. At this point, your views should be similar to the following:
    image
  7. I assume you have a working Product class--Product.h and Product.m, and three image files representing the products in your application. Import the Product source files and the three image files into your project by dragging them to the left panel. You will be prompted through check boxes on whether files should be created during the import and whether they should be added to the targets; check these boxes. Refer to the screenshot below (add the source files under the main folder, add the image files under "Supporting Files"):
    image
  8. Create a new Objective-C class (File->New->File) whose superclass is UIViewController; call that class ProductViewController.
  9. After creating the class, associate it to the second view. Do this by selecting the View Controller of the second view (dark blue top most tab of the view), click on the Identity Inspector on the right panel, and type in (or select) the correct class name. Refer to the following screenshot:
    image
  10. The ProductViewController needs to have the following properties in its header file:
    image
  11. Make sure that the segues have unique identifier values; e.g., "first", "second", and "third". Just click on the segue with the Attributes Inspector displayed to set the identifier value.
  12. In ProductViewController.m (you need to think and write code here based on what is indicated, not just copy-and-paste),
  13. For ViewController.m, refer to the following code (here, you can copy-and-paste, perhaps revise some variable/identifier names/strings after pasting):
    #import "ViewController.h"
    #import "ProductViewController.h"
    #import "Product.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    Product *apple;
    Product *orange;
    Product *pomelo;
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
        // create product objects here
        apple = [Product alloc];
        apple.name = @"Apple";
        apple.imgFileName = @"apple.jpeg";
        orange = [Product alloc];
        orange.name = @"Orange";
        orange.imgFileName = @"orange.jpeg";
        pomelo = [Product alloc];
        pomelo.name = @"Pomelo";
        pomelo.imgFileName = @"pomelo.jpeg";
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString:@"first"])
        {
            [[segue destinationViewController] setTheProduct:apple];
        }
        if ([[segue identifier] isEqualToString:@"second"])
        {
            [[segue destinationViewController] setTheProduct:orange];
        }
        if ([[segue identifier] isEqualToString:@"third"])
        {
            [[segue destinationViewController] setTheProduct:pomelo];
        }
    }
    
    @end
    
  14. Build and debug accordingly, then execute.