You are on page 1of 7

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

… #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; } ...

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];

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

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

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> . This makes it easier to modify the app..0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1. In our"> <plist version="1. we can read from a text file.. The structure of the file is as follows: <?xml version="1. each view containing a list of items is specified in an XML file.0.0//EN" "http:// www. Specifying Data Instead of hard coding arrays in the viewDidLoad method.

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

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

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