CocoaCoder

  • Accessing AppDelegate instance

    AppDelegate object can access from any class in the same application like below. Methods or properties shared between controllers can be defined under application delegates. SomeAppDelegate *appDelegate = (SomeAppDelegate *)[[UIApplication sharedApplication] delegate];

  • How to access special directory on the iphone device

    Use NSSearchPathForDirectoriesInDomains(). First argument “NSDocumentDirecotry” is the key to specify special directory, in this case Document directory under the application. The method returns absolute path expression. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSLog(@”NSDocumentDirectory is %@”, documentsDirectory);

  • Repeating background image in native iPhone app – Stack Overflow

    Apparently a UIColor is not necessarily a single color, but can be a pattern as well. Confusingly, this is not supported in Interface Builder. Instead you set the backgroundColor of the view (say, in -viewDidLoad) with the convenience method +colorWithPatternImage: and pass it a UI Image. For Instance:

  • Applying animation while resizing or moving the view

    Animation can be applied while its frame, bounds, center, transform, alpha… is being changed.  The key is set start and end values between beginAnimations and commitAnimations, so called animation block.

  • Create alert dialog

    UIAlertView takes care of this UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Alert View” message:@”Here is an alert message” delegate:nil cancelButtonTitle:@”Cancel” otherButtonTitles:@”OK”, nil]; [alert show]; // Since alert object is allocated above, it must be released here [alert release];