Jan 272012
 

I have to write down all tips to save time in the future, some may look like naive but thinking of I’m such a newbie in iOS development, nothing was easy to me.

  1. Hide keyboard whenever background touched in a storyboard
    • original posts are here:
    • idea:
      • Change the specific view from UIView to UIControl so to enable interactive, this has to be done by selecting the view from docking area instead of the Interface Builder to me
      • add a method to resignFirstResponder for current first responder
      • link the event to the method, this can be done in Connection inspector, click and drag the “+” sign on the right of “Touch Down” event to the view controller, then in the pop-up window choose the method you created just now
  2. Save and load simple application settings
    • original post is here:
    • idea:
      • I decided to create an object class to manipulate registries as I need to use it more than one place
      • form a file name for registry
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *registryFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"registry.file"];
      • save to registry
      •     NSMutableDictionary *dict = [[NSMutableDictionary alloc]  init];
            [dict setValue:[textfield1 text] forKey:@"key1"];
            [dict setValue:[textfield2 text] forKey:@"key2"];
         
            [dict writeToFile:[self registryFileName] atomically:YES];
      • load from registry
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:[self registryFileName]]
  3. create a right button on a UINavigationItem
    • original post is here:
    • idea
      • add the button after view loaded (viewDidLoad)
            self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
                                                      initWithTitle:@"Save"
                                                      style:UIBarButtonItemStyleBordered
                                                      target:self
                                                      action:@selector(saveKeys:)];
      • remember create a “saveKeys” method to finish whatever you want to do, but don’t forget this: (to emulate the “Back” action since I want to close the view after “Save”)
            [self.navigationController popViewControllerAnimated:YES];
      • and reset the button while view is unloaded (viewDidUnload)
            self.navigationItem.rightBarButtonItem = nil;
  4. singleton
    • original post is here:
    • idea
      • dig out the concept by yourself!
      • too much code, haven’t figured out what should be posted here

    I will post more here after sort couple of things out.

  5 Responses to “iOS development tips”

  1. I DO NEED TO FIND A PLUGIN FOR PASTING CODES TO WORDPRESS NOW!!!!

    Alright, I know this could be my 3rd or 4th time mentioning this, but never got it done …

  2. […] comes the second part of ios development tips which follows first part, I’m starting over the number now so to ease my […]

  3. I updated my post (format only) after installing a code syntax plugin, it doesn’t work quite well with line break, but highlight thing is good.

    I should find a new theme now to make my page wider – thinking of most people in the world should be using a machine with wide screen (wide means wider than 800 pixels.

  4. I expanded width of the content column from 500+ pixels to 700+ pixels, which makes the whole page 900+ pixels width, seems workable. I will keep this one running before find a good theme (better with flexible width).

  5. Switched to the new theme.

Sorry, the comment form is closed at this time.