1 / 43

CSCI 4802 / 5802

CSCI 4802 / 5802. Computer Science iPhone & iPad Apps For Beginners Lesson 2 February 28, 2011. This Week’s Lesson. Grades Dates Review Last Week This Week. Grades. BlackBoard Midterm, Final, HWK and Projects == 25% Three iPhone Groups 1 Droid and 1 Win7 HWK == in Class

onslow
Télécharger la présentation

CSCI 4802 / 5802

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 4802 / 5802 • Computer Science • iPhone & iPad Apps For Beginners • Lesson 2 • February 28, 2011

  2. This Week’s Lesson • Grades • Dates • Review Last Week • This Week

  3. Grades • BlackBoard • Midterm, Final, HWK and Projects == 25% • Three iPhone Groups • 1 Droid and 1 Win7 • HWK == in Class • Exams - Hand’s On.

  4. Dates • Midterm • Final • Final Presentations

  5. Last Week • I will slowly go through last week • Will not always go this slow. This is ONE TIME • I see we have three groups • Will finalize teh groups after this week’s HWK

  6. Starting iPhone App Dev • The two tools you’ll use for iPhone Apps are • Xcode Interface Builder: 6

  7. Asked you to hack my App • The ubiquitious Hello World App • The 1st program we write when starting new languages • I had you change it • 3 - groups 7

  8. Click Command/Shift/N to open up the New Project Window. Dr. Lewis’ screen automatically highlighted the View Based Application. Yours may be different so before selecting your default App make sure that, for this project, your View Based Application is selected. Name it helloWorld_001 and save it on your desktop. Click here for Mac Keyboard Symbols 8

  9. Open the “Classes” Folder: • Upon saving your project to your Desktop it instantiates a project named helloWorld_001 as indicated by the name on the top of the widow. Open up the Classes folder. Don’t ask yourself what the classes folder means – just open it. I due time you will know a ton about what the classes folder stores but for now. Let’s move forward. 9

  10. Select the ViewController.h file. It should be named helloWorld_001ViewController.h unless you named it somethingElseViewController.h. 10

  11. In the @interface add an IBOutlet UILabel *label; I’m going to explain this step in a little more detail because this is our first code that we are writing. Also, Outlets and Actions are a very big deal in iPhone Apps. 11

  12. The two // tells your computer when it compiles and translates your code into an iPhone app that anything that follows // on that line must be ignored. 12

  13. Next we see #import <UIKit/UIKit.h> that imports into your code called “classes” that means that you do not have to write or rewrite really technical code each time you want to take advantage of really cool ways to design your iPhone interface, present data to the user or to respond to user input. 13

  14. Next we see @interface helloWorld_001ViewController : UIViewController { • The “@interface” directive tells Xcode we have interface stuff to tell it concerning helloWorld_001 that will be in enclosed in the curly brackets {. But look at your screen right after the { following @interface helloWorld_001ViewController : UIViewController { – its empty! We know what we want to do though and that is say “hello” to the word from inside our iPhone. Now that we’ve got the compiler’s attention with the @interface directive we want to tell it that we first want our Interface Builder Outlet IBOutlet to say something and that something will be written on a UI (Remember UI stands for User Interface) UILabel So let’s get to it! 14

  15. IBOutlet UILabel *label; • Please make sure you do not forget the semicolon “;” at the end of the line as this tells the compiler you’re done talking to it for the moment. Don’t worry about the “*” we type before the word “label” we’ll get into this later. 15

  16. Add an Action to a button and copy it: • Now that we’ve written our first line of code IBOutlet UILabel *label; in Step 5 we need to say one more thing here. Specifically we want to have the button on our iPhone screen use methods that Apple has already coded for us. We want to add an IBAction we’ll name “hello” to have access to all the bells and whistles Apple gives us. Don’t worry about the minus sign and other items I have not explained, this is good for now. To do this we write after we close the curly brackets: • - (IBAction)hello:(id)sendr; • Again, please make sure that you remember to put the semi colon at the end of the line. Then I want you to highlight the line exactly as shown in Figure 2-06. Using your keyboard enter Command > C at the same time. These 2 keystrokes are depicted in Figure 2-06 as C and this will copy the highlighted text on the line you’ve just written. You can use your mouse to copy it, but I really do not want you to do it this way, by choosing Edit > Copy. 16

  17. Copy this last line of code by entering Command/C. 17

  18. Save your work by entering Command/S. 18

  19. Select the ViewController.m file. It should be named helloWorld_001ViewController.m unless you named it somethingElseViewController.m. Click under the @implementation code and paste the code you copied by entering Command/S. 19

  20. Delete the semicolon at the end of the line. We do this because we do not want the code’s instructions to end here. We want to print out to the iPhone screen the words “Hello World!”. 20

  21. So we add enter label.text = @”Hello World!”; But I asked you to change it to ”I refuse to Tweet” 21

  22. Save your work by entering Command/S. 22

  23. Select the Resources Folder and select the ViewController.xib file to open the Interface Builder. 23

  24. Drag out a label from the Library. 24

  25. Drag out a Buttonfrom the Library. 25

  26. Take the print out of Label and Enter ”Yo Dude!” into the Button 26

  27. Start off by clicking on the Xcode icon and it brings up the Welcome to Xcode Screen. 27

  28. Start off by clicking on the Xcode icon and it brings up the Welcome to Xcode Screen. 28

  29. Start off by clicking on the Xcode icon and it brings up the Welcome to Xcode Screen. 29

  30. Start off by clicking on the Xcode icon and it brings up the Welcome to Xcode Screen. 30

  31. But Before we do this week:Quick Review: Theory

  32. Classes Have 2 Parts • In Objective-C, classes are defined in two parts: • An interface that declares the methods and instance variables of the class and names its superclass • An implementation that actually defines the class (contains the code that implements its methods)

  33. Classes Have 2 Parts • In Objective-C, classes are defined in two parts: • Header File .h • Implementation File .m

  34. Classes Have 2 Parts • In Objective-C, classes are defined in two parts: • @interface - Define methods here • @implementation - Build Methods here

  35. Classes Have 2 Parts • In Objective-C, classes are defined in two parts: • @interface - Define a cookie cutter • @implementation - Build a cookie cutter here

  36. Object Orientated Programming • Based on the notion that a software system can be composed of objects that interact with each other: • The syntax for sending a message to an object: •  [objectName message];

  37. Object Orientated Programming • The following code declares the variable 'button' as an object •  id button;

  38. Classes • A class in Objective-C is almost like an object • Just like in C except that in addition to variables, in Objective C a class also has has code • We call this method implementations • When we call an instance of a class an object

  39. @ is used a lot in the objective-C world. Here's a partial list of commands that use it: • @implementation, @interface, @end, @synthesize, @dynamic, @public, @private, @property • These are used to define a class and its properties. Many are new in Objective-C 2.0, and are used to indicate the type of a property for getter and setter generation, etc.

  40. Exam Question • One Editable iPhone Lesson: Know for the exam. See pic on Page 51.

  41. HWK 1 For Next Week • Two parts • http://www.rorylewis.com/docs/02_iPad_iPhone/06_iphone_Movies/004_helloWorld_004.htm • This is only part 1 (Page 72)

  42. HWK 1 For Next Week

  43. Next Two Week’s Lesson • Switch View • iPhones ability to Switch Views is critical in distinguishing from anything else before it. • We use pictures • Three different methods

More Related