1 / 13

Basic Interaction

Basic Interaction. From Beginning iOS 4 Development (Chapter 3 and 4) and The iPhone Developer’s Cookbook (Chapter 2). iPhone Application Skeleton. Main.m Creates primary autorelease pool Invokes application event loop. MyAppDelegate.h MyAppDelegate.m

oma
Download Presentation

Basic Interaction

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. Basic Interaction From Beginning iOS 4 Development (Chapter 3 and 4) and The iPhone Developer’s Cookbook (Chapter 2)

  2. iPhone Application Skeleton • Main.m • Creates primary autorelease pool • Invokes application event loop • MyAppDelegate.hMyAppDelegate.m • Sets how program react at critical points • Initialize window system at start • Wrap up at termination • Handles memory warnings • MyViewController.hMyViewController.m and MyViewController.xib • Defines your application • How application responds to events • What objects are used in the application

  3. Sandboxes • Security feature • Limits application’s access to file system, network resources and hardware • Characteristics • May not access any other programs sandbox • May not share data • May not read or write to files outside of sandbox • You own your own library, document and /tmp folders

  4. Model – View - Controller • Known as MVC • Separates how object looks from how it behaves • Enables independent updates of program components • Model –classes that hold application data • View –windows, controls and user interactive elements • Controller – binds model and view together

  5. Outlet Pointer that points to an object Used to make changes to an object Created in Xcode Linked in Interface Builder Example: coding a change of value in a display label. Need an outlet to connect to the label to make coded changes.

  6. Creating an Outlet • Declare in the .h file (*ViewController.h) Add UILabel *statusText; to @interface Add @property and the action • Implement in the implementation file or .m file (*ViewController.m) Add @synthasize (to tell compiler to create assessor and mutator methods) Add action code Dealloc

  7. Accessors and Mutators Also known as getters and setters Pairs of methods used to set and retrieve values for each of a class’s instance variables. Now using @property in the .h file and @synthasize in the .m file replaces the methods for creating getters and setters.

  8. Application Delegates • Classes that handle things on behalf of another object • UIApplication class—iPhone has one and only one UIApplication • Handles the application loop and routing input to the right controller class • Works behind the scenes

  9. Connecting Outlets • Must create outlet and save in Xcode before connecting • In Interface Builder, after adding object(s) to the view • Hold down control key, click on File’s Owner and drag to object to be linked in View. • Release and will see a list of the outlets you have created • Select the appropriate outlet

  10. Adding Actions Open connections inspector (2) Look under Events and select the event you wish to link Click circle next to event and drag to File’s Owner Icon and select the pre-coded method (created earlier in Xcode)

  11. Active, Static and Passive controls • Active—interactive—does something when interacted with (example button) • Static—may change programmatically, but the user can not interact with directly (example label) • Passive—interactive—but does not trigger an action (example text field) Many of the controls may be used in any of the preceding ways All are subclasses of UIControl and are capable of having actions. Most may be used passively, or made inactive (static) when created or at runtime.

  12. Behavioral differences between Mac and iPhone controls • iPhone controls may trigger multiple actions depending on how touched, Mac controls usually have one action that is triggered. (click) • iPhone has no physical keyboard—just a view filled with a series of button controls.

  13. Some Useful shortcuts in Interface Builder 1 –property Inspector 2 –connections Inspector 4 –identity Inspector = -to size to fit

More Related