We've posted an updated set of examples based on our iPhone App Development Fundamentals LiveLessons videos, which are available to video subscribers at http://www.SafariBooksOnline.com/. The updated examples are available on this page when you are registered and logged into the site. These updated examples were built in the iPhone SDK 3.1.3.
Here are some additional notes from building these updated apps against the iOS4 SDK:
Each of the apps built fine after changing the project settings to the 4.0 SDK, with the following exceptions:
We are rebuilding the apps from scratch now using the iOS 4 SDK and will post notes about changes to the app templates and the steps required to build each app as soon as we have them.
Due to a change in the Utility application template, this app will have issues. In 3.2, when a new app was created, MainViewController would get instantiated in the application delegate like so:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
}
In 4.0, the line is removed:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the main view controller's view to the window and display.
[window addSubview:mainViewController.view];
[window makeKeyAndVisible];
return YES;
}
MainViewController is instead instantiated in MainWindow.xib. You'll encounter this problem if you follow the steps that we provided in the Flag Quiz chapter and you're using iOS SDK 4.x. The fix is to either add the missing lines of code to the app delegate, or to add a new MainViewConroller instance to MainWindow.xib (with the appropriate connections).
UPDATED TIP CALCULATOR APP (IOS 4.2):
The TipCalculator app broke in iOS 4 because of a subtle change Apple made to how UITextFields work. Under iOS 4, when we tell billField to become the first responder (and make the keyboard come up), nothing happens because it has the "User Interaction Enable" property disabled. Previously in iOS 3, this was not the case.
The simplest way to make the app work is enable that property (in MainWindow.xib, select billField and open the Inspector. Check "User Interaction Enabled"). However, this will let the user change the cursor in billField manually, which is undesirable.
Here are some steps to make TipCalculator work under iOS 4, while still maintaining full functionality:
1) Open MainWindow.xib and make a duplicate of the top UITextField and move it to the bottom of the screen. Open the Inspector, and check "User Interaction Enabled" and "Hidden" for the new UITextField.
2) In the "Connections" tab of the Inspector, remove the "Editing Changed" connection for the origional UITextField. Also delete the text in the new UITextField.
3) Open Controller.h. Add the line
IBOutlet UITextField *hiddenField;
in the interface declaration.
4) In MainWindow.xib, connect the "hiddenField" outlet of "Controller" to the new UITextField.
5) Replace Controller.m with the version in the new project that's posted at
http://www.deitel.com/bookresources/iPhoneFP/TipCalculator.zip
Basically, the way Tip Calculator previously worked was as follows:
User touches button -> billField modified -> calculateTip: called -> bill total updated -> billField modified -> calculateTip: called again -> method exits because of "toggle" variable.
Here's the new flow of execution:
User touches button -> hiddedField modified -> calculateTip: called -> bill total updated -> billField modified.
This is a cleaner way of doing things, and as a bonus it doesn't break on iOS 4.