Trimming strings in Objective-C / Cocoa

Jul 30 2009 Published by Eneko Alonso under uncategorized

  1. returnString =  [returnString stringByTrimmingCharactersInSet:
  2.                  [NSCharacterSet whitespaceAndNewlineCharacterSet]];

Very intuitive, huh?

No responses yet

Placing a UIActivityIndicartorView on a UIBarButtonItem

Jul 26 2009 Published by Eneko Alonso under uncategorized

Have you seen those iPhone apps with a reload button that switches itself to an animated activity indicator while the reload action is being performed?

Here is how to do that. Place this code on your ViewController:

  1. - (void)showReloadButton {
  2.   UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc]
  3.     initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
  4.                                         target:self
  5.                                         action:@selector(reload:)];
  6.   self.navigationItem.rightBarButtonItem = refreshItem;
  7.   [refreshItem release];
  8. }
  9.  
  10. - (void)showActivityIndicator {
  11.   UIActivityIndicatorView *activityIndicator =
  12.     [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  13.   [activityIndicator startAnimating];
  14.   UIBarButtonItem *activityItem =
  15.     [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
  16.   [activityIndicator release];
  17.   self.navigationItem.rightBarButtonItem = activityItem;
  18.   [activityItem release];
  19. }
  20.  
  21. - (IBAction) reload {
  22.   // Do your reload stuff
  23. }

Seen here.

No responses yet

MyGameOfLife source code

Nov 28 2008 Published by Eneko Alonso under uncategorized

Almost a year ago I was learning some Cocoa and I decided it will be fun to implement a Cocoa based version of Conway’s Game of Life. Back then I didn’t publish the source code, not for any special reason. So now I have just uploaded it to Google Code. It’s not fully functional, since the last time I worked on it I was creating an structure editor. My idea was to create a library of structures, with drag&drop and import/export options.

If you are interested on working on the project, let me know :)

http://code.google.com/p/my-gameoflife

My Game of Life

No responses yet