CS 696 Mobile Application DevelopmentFall Semester, 2010Doc 13 Settings, Utility, Rotation, TablesOct 12, 2010Copyright ©, All rights reserved. 2010 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent (http://www.opencontent.org/openpub/) license defines the copyright on this document.References2Beginning iPhone 3 Development: Exploring the iPhone SDK by Jeff LaMarche, and David Mark,Table View Programming Guide for iOS3Convert4 float fahrenheitValue = centigrade *(9/5)+32;centigrade = 100;thenfahrenheitValue = 132???5Fear6I have been working for two weeks on this project and fear making changes7SnapshotsSave project stateRestore part or all of project to saved stateMulti-file undo/redoFIles stored locallyFor individual use onlyList of Snapshots8Diff9Source Control10CVSSubversionMore control than SnapshotsSupports multiple developers on same projectSubversion11Starting new repositorysvnadmin create repositoryNameConfiguring Xcode to do the right thing12Adding a Repository to Xcode13Repositories Window14Tricky Part15Import projectThen Check it outWork on the checked out projectAdding new Files to project16Have to add them to repository tooCommit & Update17Commit - send changes to repositoryUpdate - Fetch latest version from repositoryRefresh - update file statusMore Information18Xcode Source Management Guide19Settings20Problem With Project TemplatesToo much magicNot enough understandingHow do we just use Standard Settings App?21Just add Settings.bundle to projectWorks for any projectHow do we read the values22NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; username.text = [defaults objectForKey:kUsernameKey]; password.text = [defaults objectForKey:kPasswordKey];Changing Values23NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:@"Roger" forKey:kUsernameKey];[defaults synchronize];Details24iOS Application Programming GuideChapter 6 Implementing Application PreferencesNSUserDefaults class DocumentationThat it for Settings25except for iOS 4Background Process26iOS 4Device must support multitaskingApp Delegate Methods27 ▪ application:didFinishLaunchingWithOptions: ▪ applicationDidBecomeActive: ▪ applicationWillResignActive: ▪ applicationDidEnterBackground: ▪ applicationWillEnterForeground: ▪ applicationWillTerminate:Launching the app28UIViewController methodviewDidLoad is calledMoving to the Background29Resuming Foreground30UIViewController methodviewDidLoad is not calledNotifications31ObserverRegisters with Notification centerFor notification from a sourceMust unregister before deallocSourceWhen changes sends messageto observersCan create own sourcesNotificationCenter32Getting the Notification Center + defaultCenterManaging Notification Observers – addObserver:selector:name:object: – addObserverForName:object:queue:usingBlock: – removeObserver: – removeObserver:name:object:Posting Notifications – postNotification: – postNotificationName:object: – postNotificationName:object:userInfo:Notification Example33- (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(defaultsChanged: ) name:NSUserDefaultsDidChangeNotification object:nil];}- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver: self]; [super dealloc];}Notification34Receive notifications when application becomes activeReceive notification for each time you registerReceive notification for each changeHow to find out about Notifications35Each Class documents the notification it will send36Utility37Utility AppsFlip Button38- (IBAction)showInfo:(id)sender { FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil]; controller.delegate = self; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; [controller release];}Done39Just a buttonLinked to method done:FlipsideViewController.h40@interface FlipsideViewController : UIViewController { id <FlipsideViewControllerDelegate> delegate;}@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;- (IBAction)done:(id)sender;@end@protocol FlipsideViewControllerDelegate- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;@enddone:41- (IBAction)done:(id)sender { [self.delegate flipsideViewControllerDidFinish:self]; }flipsideViewControllerDidFinish42- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller { [self dismissModalViewControllerAnimated:YES];}43Rotation44How to keep things synchedIf used multi-views for single view rotation Keep portrait & landscape view synched when rotateWhen switching tabsMake sure the new view is in the correct orientationHow do we know when switch tabs?UITabBarControllerDelegate45Managing Tab Bar Selections – tabBarController:shouldSelectViewController: – tabBarController:didSelectViewController:Managing Tab Bar Customizations – tabBarController:willBeginCustomizingViewControllers: – tabBarController:willEndCustomizingViewControllers:changed: – tabBarController:didEndCustomizingViewControllers:changed:46Tables47Table View ReferenceTable View Programming Guide for iOSClass documentationTable View Styles - Plain48Plain Section Index Selection ListTable View Styles - Grouped49GroupedGroupedWith header &FooterCell Styles50No Subtitle (default) With SubtitleCell Styles51Right-aligned subtitle Contacts formatParts of a cell52With ImageEditing modeAccessory Views53Disclosure indicator - Leads to another tableDetail Disclosure button - Leads to detail viewCheck Mark - appears when user tabs on itemCustom Cells54Customization can be done in code or in the Interface BuilderPerformance Issues55Reuse CellsLayout custom cells onceOpaque subviewsTable View Delegate & Data source56Both requiredData source provides information about the dataExample From textbook57@interface Simple_TableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {}@property (nonatomic, retain) NSArray *listData;@end58@implementation Simple_TableViewController@synthesize listData;- (void)viewDidLoad { NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy", @"Sneezy", @"Bashful", @"Happy", @"Doc", @"Grumpy", @"Dopey", @"Thorin", @"Dorin",
View Full Document