IOS objective-c代写:iPhone Programming Assignment 2

iPhone Programming – Spring 2017

Nathan Hull

Assignment 2 – Due: Wednesday, March 1st


In this assignment you will create your first iOS application.

In brief, you will create a program that displays the same product names, descriptions, costs, and num-on-hands which you used in the first assignment, and allows you to increment or decrement the count for any particular product. In addition, each product should have an associated picture.

Eventually, your layout will look something like the picture at the right (from the Storyboard). Feel free to choose the name of your own store, choose your own products and design your own layout.

Minimally, your screen should have a picture which is associated with the product and all of the associated information for that product.

It should then have four Text Fields which are set up to contain the Product, the Description, the Cost and the Num-on-Hand.

Next, there should be two buttons which allow you to display data from your array either going forward through the array, or backward. (Of course, if you come to either end of the array, the corresponding button won’t do anything!)

Finally, there are an “Increment Count” button that increases by 1 the Count for the currently displayed Product, and also a “Decrement Count”. Note that the count can’t be less than 0.

Also note that before the user hits either button, you are not required to display any contents from the array. You may just leave in the “Placeholder” names created in IB.

However, before you can use Interface Builder, you will need to start by creating the project and its ViewController header file.

iphone7

Part One: First, in Xcode, you will be creating a New Project. Choose “File:New Project”, then pick “iOS Application” on the left and from the right panel choose to create a new “Single View Application”.

In all probability, you will probably want to begin to build your project WITHOUT referencing any real data. This will allow you to get your Interface to work without having to worry about how to attach the underlying data structure. So, as a suggestion, you might want the “Backward” button to simply put the string “from Backward” into the first three text fields. It might be amusing to have the “Increment Count” button actually increment the count which is displayed. (Obviously, this will be necessary in Part Two of the assignment).

Next, you will want to create an icon for your project. In order to submit an application to Apple’s App Store, you have to give them a 1024 x 1024 image of your icon. Thus, most projects create their logo in this high resolution, and then reduce it to the various sizes that Apple needs for the App Icon. You should also create a Launch Icon that duplicates your first screen. (See Apple’s Docs on the subject for details). Save your images as PNG graphics, and drop them into Xcode’s images.xcassets folder for your project. (Also, here is a cool Photoshop template which generates the various icon sizes for you. Or, you can also try this online version which takes a 1024×1024 image and converts it for you).


Part Two: After you have gotten your interface to work in some rudimentary fashion, you will turn to the data structure. In this homework, instead of a NSMutableDictionary Object, you will hold your data in a NSMutableArray. This will allow you to access your data ‘in order’. Note that you may want to also carry the named of the associated image for the product. Thus, a possible data set might now look something like this:

Position

Product

Description

Cost

Num on Hand

Image

0

iPhone 7

Apple’s iPhone 6 minus plug

769.00

2

iphone7.png

1

Galaxy Note7

Samsung’s Exploding Phone

850.00

90

galaxy.png

2

40-inch TV

Sony’s LED TV

298.00

89

tv40.png

3

Kindle Reader

Amazon’s E-Reader

79.99

200

kindle.png

4

Apple Watch

Series 2 – Aluminum Case

299.00

0

apple_watch.png

 

There are also many methods for Arrays which are given to you in the Foundation Framework. For example, one method is Apple’s definition of addObject:

— (void)addObject:(id)anObject

In our book, “Programming in Objective-C” by Stephen Kochan, the author gives the following example of this method:

[primes addObject: [NSNumber numberWithInteger:2] ];

You may choose to simply define the array and its initial contents all at once.

Part Three: Add an extra button called “Add Record”. In this case, you would be taken to a new View (with a different design) where you would be allowed to enter information into four Text Fields, after which you would press an “Enter” button. The information would be added into a new object at the end of your array, and you would be taken back to the original View. In this case, a ‘blank’ image would be added for your product (e.g., an image which is all black or an image that simply says ‘Image Not Available’.)

Note: Disable and change the text color of the “Backward” button if you are at position 0 of the data and Disable and change the text color of the “Foreward” button if you are displaying the last position of the array. You will do this by setting the TitleColor of the button in question and changing its SetEnable property. This will give a visual clue to the user that the button isn’t operational. (There may be more than one way to accomplish this goal.)


Extra Credit (3 points): In addition to the “Backward” and “Forward” buttons, create a slider which controls the display of the data in your array. If the slider is all the way to the left, the data in position 0 is displayed. Note that if it is all the way to the right, it should display the data for the last position added (as per the first extra credit). Thus, you have to take into account that the subscript range may vary over the course of the execution of your program. Make certain that you change the look and action of the respective buttons at the beginning or the end of the data as above.

Extra, Extra Credit (3 points): Add yet another button that is labeled “Stats” which displays another View which shows two numbers: The current number of records, and the total number of times that the “Increment Count” button has been pressed.


Zip your entire project, and post it on “NYUClasses”.

This assignment is a work-in-progress, so check back for any additions, corrections, clarifications, helpful hints, etc., etc.