Académique Documents
Professionnel Documents
Culture Documents
March 5, 2012
Introductions
Speakers:
Chris Rider Northern Kentucky University Center for Applied Informatics Senior Technology Architect riderc1@nku.edu
Eric Rolf Northern Kentucky University Center for Applied Informatics Mobile Application Developer rolfe1@nku.edu
Resources
http://developer.apple.com/iOS iPhone Programming, The Big Nerd Ranch Guide Joe Conway & Aaron Hillegass Programming in Objective-C Kochan http://www.raywenderlich.com Excellent iOS5 tutorials! Stanford free iOS lectures. Worth the time to watch!
Introduction
iOS is the operating system that runs iPhones, iPod Touches, iPads, and Apple TVs. The language used to develop software for iOS is Objective-C. This class will teach you how to get started but will not have time to teach you everything.
What is iOS?
iOS is an operating system its a subset of Mac OS X. The iOS SDK is the software development kit that allows application programs to utilize classes and frameworks provided by the SDK. This class will focus on iOS SDK 5. iOS is multitasking and runs on several different devices (iPhones, iPod Touches, iPads, and Apple TVs). Apple provides an IDE called Xcode. Xcode is the IDE used by iOS (and OS X) developers. Xcode provides an interface to the compiler, editor, debugger, and code profiling tools.
Device Features
For the rest of the presentation, assume we are discussing iPhones, iPads, and iPod Touches. Although Apple TV runs iOS, Apple currently does not allow developers to create custom code for this device (yet). SQLite for structured data storage Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) GSM Telephony (hardware dependent) Bluetooth, EDGE, 3G, and WiFi (hardware dependent) Camera, GPS, compass, and accelerometer (hardware dependent) Rich development environment including a device simulator, tools for debugging, memory and performance profiling
Xcode
Launch Xcode
After youve downloaded and installed Xcode, launch it You are presented with the Welcome screen:
Create a new project Connect to a repository Learn about using Xcode Go to Apples Portal
Project Template
There are several predefined templates to help you get started on a new project For now, click on Single View Application
Project Options
The Product Name is the name of your app Company Identifier is your organization name such as edu.nku (reverse domain notation) Class Prefix (leave empty) Device Family: iPad, iPhone, Universal (Universal means that a single binary will have screens for iPhone, iPod Touch, and iPads) Storyboards Automatic Reference Counting Include Unit Tests (leave unchecked as we are not using)
Source Control
Asks for a location for Source Control By Default, it will use a local GIT repository New developers not used to source control this is extremely useful! It keeps track of versions, lets you see whats changed, and will undoubtedly be used in any team project you run into in the real world GIT and Subversion are two popular source controls systems there are many others to choose from
Where do I start?
ViewController.h
Remember that ObjectiveC is an extensive to the C language The @ symbol denotes an ObjectiveC keyword @interface is the start of a class. @interface Classname: Superclass Anything between the declaration and end is part of the class
A property is an attribute of the class Getters and Setters are automatically created for you Weak is a memory management term we will not be discussing this in depth Nonatomic has to do with adding mutexes around your getters and setters we will not be discussing in this class IBOutlet stands for Interface Builder Outlet. Interface Builder still exists in iOS5 we are using Storyboard instead. We will not be discussing it much in this class (Interface Builder is your interface to working with nibs)
TouchUpInside Actions
TouchUpInside events occur if you touch a button and lift off while inside the button This corresponds to a user tapping a button Click on the Hello button On the far right, locate Touch Up Inside Left click-drag this over to your ViewController.m Notice it creates some code Do the same for the goodbye button
IBAction
You created two IBActions Actions signify something that happens when you do something like push a button When you push a button, it fires the action These are currently empty methods
(IBAction)helloPushed:(id)s ender { } (IBAction)goodbyePushed:( id)sender { }
Tab Controller
If youve ever used an iOS device, you have come across apps that use the tab controller. Several of the built in apps (such as the phone app) use this controller For the next session, we are going to create a simple tab controller
Set Options
For product name, call it tabDemo Whatever you used for Company Identifier should be set if not, edu.nku is ok Leave Class Prefix blank For Device family, choose iPhone (to keep it simple) Enable Storyboards and Arc Do not select Unit Tests as we are not going over them
Create
Take the default options, click the Create button
Select Relationship
Select ThirdViewController
From the combo box, scroll until you find ThirdViewController This will let us do any custom actions we might need to do Remember: ThirdViewController has all of the methods and properties of a UIViewController!
Check it out
This is what we did in the previous slide Since the Navigation Controller is a container, there is a relationship between the Nav controller and the table view controller. (Noted by the connecting arrow)
Attributes Inspector
New file
Objective-C Class
ThingsViewController
Click on ThingsViewController.h
Add an NSMutableArray pointer This arry will contain Things objects it will be the main data model for the app. #import <UIKit/UIKit.h> @interface ThingsViewController : UITableViewController @property (nonatomic, strong) NSMutableArray *things; @end
New File
Objective-C Class
Class Thing
Create
Modify thing.h
Modify thing.m
Modify AppDelegate.m
The AppDelegate will create a Thing array and add some sample data to it The first thing you need to do is click on AppDelegate.m At the top of the file, add:
#import Thing.h #import ThingsViewController.h
The imports tell the delegate what these classes are so we can use them Add an instance variable named things (It is an NSMutableArray pointer)
AppDelegate.m
didFinishLaunchingWithOptions method
tabBarController
UITabBarController *tabBarController This line of code lets us access the storyboards initial view controller (the tab bar controller) We now have a pointer to it.
navigationController
UINavigationController *navigationController Using the tabBarController pointer, we are just getting a pointer to the navigationController
ThingsViewController *thingsViewController
Next, we get access the the thingsViewController We are not done yet!
ThingsViewController.m
Find the method numberOfSectionsInT ableView
ThingsViewController.m
Change numberOfRowsInSection Notice what we are doing with the return We are returning a count of the number of objects in the things array. (In our example, this is 3)
ThingsViewController.m
Modify cellForRowAtIndexPath We are interfacing with the ThingCell we defined earlier We then add the name and how many (in this case, we are converting the returned value from an NSInteger to an NSString)