iPhone 101 Get Started.pdf | Xcode | Ios

Simple Navigation Template App

In this document, we list the relevant code sections for a simple Navigation template based app. In such apps, each view is a list of items. Clicking on an item takes you another view of a list of items, or more details related to the clicked item. These lists, hence, are grouped hierarchically.

Source Code
The relevant sections of the source code sections: 1. main.m 2. MyNav_AppDelegate 3. RootViewController

main.m
… #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } ...

AppDelegate
In the AppDelegate, the ... - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the navigation controller's view to the window and display. [window addSubview:navigationController.view]; [window makeKeyAndVisible];

self. } . nil].. .(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1.m . } // Customize the number of rows in the table view.. // Uncomment the following line to display an Edit button in the navigation bar for this view controller. ItemArray = [tmpArray mutableCopy]. NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithObjects:@"Multiplication".. // self..title = @"Mental Math". [tmpArray release]. RootViewController. @implementation RootViewController NSMutableArray *ItemArray.editButtonItem. } #pragma mark #pragma mark Table view data source // Customize the number of sections in the table view.(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { . NSLog(@"# of items in array = %d". #pragma mark #pragma mark View lifecycle // .rightBarButtonItem = self.[ItemArray count]).navigationItem.return YES. .(void)viewDidLoad { [super viewDidLoad].

return cell.(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell". // Pass the selected object to the new view controller.text = [ItemArray objectAtIndex:indexPath.(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // MultiplicationPractice *detailViewController = [[MultiplicationPractice alloc] initWithNibName:@"MultiplicationPractice" bundle:nil]. } // Customize the appearance of table view cells.[ItemArray count]). // } .row]. return [ItemArray count].NSLog(@"Number of Rows in Section: # of items in array = %d". . cell. [MultiplicationPractice release]. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier].. if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]. } // Configure the cell.textLabel. // . } #pragma mark #pragma mark Table view delegate ..navigationController pushViewController:detailViewController animated:YES]. [self.

0"> <dict> <key>Item1</key> <dict> <key>Label</key> <string>Item 1</string> <key>ShortLabel</key> <string>Item 1</string> <key>Rank</key> <string>yyy</string> <key>NextFileName</key> <string>Item1DetailData</string> <key>NextViewType</key> <real>1</real> </dict> <key>Item2</key> <dict> <key>Label</key> <string>Item 2</string> <key>ShortLabel</key> <string>Item 2</string> <key>Rank</key> <string>zzz</string> <key>NextFileName</key> <string>Item2ListData</string> <key>NextViewType</key> <integer>0</integer> </dict> </dict> .0.dtd"> <plist version="1. The structure of the file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1. In our app..apple.. Specifying Data Instead of hard coding arrays in the viewDidLoad method.com/DTDs/PropertyList-1. each view containing a list of items is specified in an XML file.. This makes it easier to modify the app.0//EN" "http:// www. we can read from a text file.

Access to components not available on the simulator. Loading your app onto the device is not a matter of simply transferring it to the device. upload it to the iOS Provisioning Portal on the developer. Register device on Portal 2.Setting the Code Signing Identity with the proper Certificate c. You create the certificate on your Mac.Mobile Provisioning Profiles: Associates Certificate with particular apps and device i. compass. So. there are 2 main concepts: 1.. But. Getting the App Ready a. Getting Xcode Ready (one time) a. Mobile Provisioning Profiles The Certificate validates that you are a bona fide developer. after it's been confirmed by Apple (all happens in real time and almost instantaneously.plist to the App ID b.Loading the Mobile Provisioning Profile (done with iTunes syncing or Xcode when device is registered to be used for development) 3. you may have to modify your code to get acceptable performance 3. There are actually a few things that need to be done so that you can transfer your app to the device. typically slower.</plist> . Getting the Device Ready (one time) a. These are mainly related to first. you will want to see it work on an actual device. your app will run on the simulator but will crash when you run it on an actual device. Then. There are 3 main steps: 1.apple. camera. at some time..com web site. You may be inadvertently using libraries on the Mac that are no available on the iphone. you download the certificate . Loading/Deploying App to Device Testing your app on a simulator is all well and good. Several reasons: 1. and second that the app can only work on registered devices. multi finger gestures. 2. So. Setting the Bundle Identifier in Info. Certificates: Validate that you are bona fide developer b. Switch build for device Getting Xcode Ready (one time) Thus. such as true GPS. ensuring that you are a valid developer. Speed of actual device is different than on the Mac. Certificates 2.

select App ID and the devices you want to associate with this profile. go to the Provisioning > Developer section of the Portal on the developer. (Later. Download profile and install into Xcode by dragging profile onto the Xcode in dock: a. Mac: UserName > MobileDevice/Provisioning Profiles (this will get transferred to your device the next time you synch with your device with iTunes) 2. The Mobile Provisioning Profiles ties the Certificate with your hardware devices and your app. you can use a name such as com. To install in the Mac OS X keychain. when preparing your app for deployment on the device.Click "New Profile. iPhone/iPad/iTouch: Settings > General > Profile Finally.) Technically this simply means that all the applications created using this bundle identifier will share the same portion of the keychain on the device. the Mobile Provisioning Profile is transferred to your device.somesite. c. Plug your app into the Mac .Once the device is registered and you have an App ID. Register devices: Register the unique Identifiers of the devices (UDID . (You can check the certificates are installed correctly by opening KeyChain Access app (Applications > Utilities ).apple.Unique Device Identifier) you want to use. Otherwise. need to: Get your Device Ready (one time) a.* (the * is a wildcard and lets you (You can check whether it's installed correctly: 1. there are 3 main steps: 1. 2.somesite. 3. to deploy your app. double click the 2 downloaded files in turn. To generate a Mobile Provisioning Profile. While the Certificate remains on the Mac. you would have to generate a new App ID for each of your applications.MyApp1 etc." and enter any Profile Name. Name: Can be anything you want to refer to the app. use this App ID for multiple applications.Bundle Seed: Select Generate New c. Xcode will look for these certificates in your Mac OS X's keychain so that Xcode can sign your application binaries. b. Then. Generate App ID a. Bundle Identifier: Use something like com.com site. and clicking on the Certificates category.along with the Apple's WWDR certificate to your Mac. b. It's best to use something that has "Developer Profile" in the name.

Get your App Ready a. (Set it.Open the Info.Xcode will recognize your device and ask whether you want to use it for development. This will deploy app to the device. b.somesite. ii.MyApp1). let it first complete it's syncing.Switch from Simulator mode to Device and compile (Build & Run). Then. and edit the Bundle Identifier key's value to be the Bundle Identifier you set when creating the App ID on the portal.Open the Project window (for example. open Xcode 1. by double-clicking the App's project icon at the top of the Groups & Files pane in Xcode. . This will match it with the Mobile Provisioning Profile on the device.i.Code Signing Identify > Any iPhone OS Device: Select the iPhone Developer Certificate c. i. Build tab 1.plist file. to com. If this device regularly syncs with iTunes. for example.

Sign up to vote on this title
UsefulNot useful