Advertisement
kristian

Stack overflow #7841116 -- BNRAppDelegate.m

Oct 20th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //
  3. //  BNRAppDelegate.m
  4. //  iTahToodle
  5. //
  6. //  Created by Kristian Freeman on 10/20/11.
  7. //  Copyright (c) 2011 redsashimi, inc. All rights reserved.
  8. //
  9.  
  10. #import "BNRAppDelegate.h"
  11.  
  12. // Helper function to fetch the path to our to-do data stored on disk
  13. NSString *docPath()
  14. {
  15.     NSArray *pathList =
  16.     NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  17.     return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"data.td"];
  18. }
  19.  
  20. @implementation BNRAppDelegate
  21.  
  22. @synthesize window = _window;
  23.  
  24. #pragma mark - Application delegate callbacks
  25.  
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  27. {
  28.    
  29.     // Attempt to load an existing to-do dataset from an array stored to disk.
  30.     NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
  31.     if (plist) {
  32.         // If there was a dataset available, copy it into our instance variable.
  33.         tasks = [plist mutableCopy];
  34.     } else {
  35.         // Otherwise just create an empty one to get us started.
  36.         tasks = [[NSMutableArray alloc] init];
  37.     }
  38.    
  39.     // Is tasks empty?
  40.     if ([tasks count] == 0) {
  41.         // Put some strings in it
  42.         [tasks addObject:@"Complete a task"];
  43.         [tasks addObject:@"Complete another task"];
  44.         [tasks addObject:@"Live long and prosper."];
  45.     }
  46.    
  47.     // Create and configure the UIWindow instance
  48.     // A CGRect is a struct with an origin (x,y) and size (width,height)
  49.     CGRect windowFrame = [[UIScreen mainScreen] bounds];
  50.     UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
  51.     [self setWindow:theWindow];
  52.    
  53.     // Define the frame rectangle of the three UI Elements
  54.     // CGRectMake() creates a CGRect from (x,y,width,height)
  55.     CGRect tableFrame = CGRectMake(0, 80, 320, 380);
  56.     CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
  57.     CGRect buttonFrame = CGRectMake(228, 40, 72, 31);
  58.    
  59.     // Create and configure the table view
  60.     taskTable = [[UITableView alloc] initWithFrame:tableFrame
  61.                                              style:UITableViewStylePlain];
  62.     [taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
  63.    
  64.     // Make this object the table view's dataSource
  65.     [taskTable setDataSource:self];
  66.    
  67.     // Create and configure the text field where new tasks will be typed
  68.     taskField = [[UITextField alloc] initWithFrame:fieldFrame];
  69.     [taskField setBorderStyle:UITextBorderStyleRoundedRect];
  70.     [taskField setPlaceholder:@"Type a task, tap Insert."];
  71.    
  72.     // Create and configure the text field where new tasks will be typed
  73.     insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  74.     [insertButton setFrame:buttonFrame];
  75.    
  76.     // Buttons behave using a target/action callback
  77.     // Configure the insert button's action to call this object's addTask: method
  78.     [insertButton addTarget:self
  79.                      action:@selector(addTask:)
  80.            forControlEvents:UIControlEventTouchUpInside];
  81.    
  82.     // Give the button a title
  83.     [insertButton setTitle:@"Insert"
  84.                   forState:UIControlStateNormal];
  85.    
  86.     // Add our three UI Elements to the window
  87.     [[self window] addSubview:taskTable];
  88.     [[self window] addSubview:taskField];
  89.     [[self window] addSubview:insertButton];
  90.    
  91.     //Finalize the window and put it on the screen
  92.     [[self window] setBackgroundColor:[UIColor whiteColor]];
  93.     [[self window] makeKeyAndVisible];
  94.    
  95.     return YES;
  96. }
  97.  
  98. - (void)applicationWillResignActive:(UIApplication *)application
  99. {
  100.     /*
  101.      Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  102.      Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  103.      */
  104. }
  105.  
  106. - (void)applicationDidEnterBackground:(UIApplication *)application
  107. {
  108.     /*
  109.      Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  110.      If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  111.      */
  112. }
  113.  
  114. - (void)applicationWillEnterForeground:(UIApplication *)application
  115. {
  116.     /*
  117.      Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  118.      */
  119. }
  120.  
  121. - (void)applicationDidBecomeActive:(UIApplication *)application
  122. {
  123.     /*
  124.      Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  125.      */
  126. }
  127.  
  128. - (void)applicationWillTerminate:(UIApplication *)application
  129. {
  130.     /*
  131.      Called when the application is about to terminate.
  132.      Save data if appropriate.
  133.      See also applicationDidEnterBackground:.
  134.      */
  135. }
  136.  
  137. @end
  138.  
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement