iPhone Programming - Spring 2009

Nathan Hull

Assignment 2- Due: Tues., Feb. 24th


In this assignment you will create your first iPhone application.

In brief, you will create a program that displays the same user names, passwords, and counts which you used in the first assignment, and allows you to increment the count for any particular Website.

Eventually, your layout will look something like the picture at the right (from Interface Builder). Feel free to design your own image and layout.

Minimally, your screen should have a picture at the top which never changes - Note that the image is placed inside of an Image View taken from the IB's Library.

It should then have four Text Fields which are set up to contain the Website, the User Name, the Password and the Count.

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 is an "Increment Count" button that increases by 1 the Count for the currently displayed Website.

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.

monster ib

Part One. First, in Xcode, you will be creating a New Project. Choose "File:New Project" and then from the left panel choose to create a new "iPhone" "Application". After these choices have been made, in the right box, select "View-Based Application".

In all probability, you will probably first want 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 512 x 512 image of your icon. Thus, most projects create their logo in this high resolution, and then reduce it (probably in Photoshop) to the 57 x 57 image you need for Xcode. Save your image as a PNG graphic, and drop it into Xcode's Resource folder for your project. Then, double-click the "Info.plist" file, and enter the icon's name in the "Icon File" location. That's it!

 


Part Two. [Note: there will be more explanation added to this section next week] 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'. Thus, a possible data set might now look something like this:

Position
Website
Username
Password
Count
0
Gmail
Frankenstein
greenaboutyou
12
1
Yahoo
Dracula
biteoutatheapple
14
2
NYU
Wazowski
Sulley1549
89
3
Amazon
Kate Monster
Monstersorri
14
4
AOL
Chocula
bad!!teeth
0

 

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 2.0" by Stephen Kochan, in Chapter 15 the author gives the following example of this method:

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

So, it is quite possible to define an array and later on add objects to the end of it. However, for the basic assignment, you may choose to simply define the array and its content all at once.

 


Extra Credit: Add an extra button called "Add Record". In this case, you would be allowed to enter information into the four Text Fields, after which you would press this new button. The information would be added into a new object at the end of your array.

Extra, Extra Credit: In addition to the "Backward" and "Forward" buttons, create a slider which controls the dispaly 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.


Zip your entire project, and send it to your TA, Adrian Secord at: s9048004 [at] cs [dot] nyu [edu]

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