Loading a Nib file, Programmatically (Objective-C)

If you want to load a Nib file at run time by simply allocating and initializing a View object, then you should take a rather strange approach to how you create your class files. Suppose you have a subclass of UIView called MyView and what you want is to allocate and initialize an instance of MyView but have MyView load its outlets and actions from a Nib file. Well, you will need to do two things:

  1. In Interface Builder, change the class name of your View object to MyView.
  2. Then you will have to override MyView’s initWithFrame method like so:

- (id)initWithFrame:(CGRect)paramFrame
{

NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"MyView"
owner:nil
options:nil];

if ([arrayOfViews count] < 1){
[self release];
return nil;
}

MyView *newView = [[arrayOfViews objectAtIndex:0] retain];
[newView setFrame:paramFrame];

[self release];
self = newView;

return self;

 

}

Then you can go ahead and initialize your view like this:

MyView *myView = [[MyView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:myView];
[myView release];

And here an instance of MyView will get added to the view of a view controller. That simple. I hope it helps some of you out there 🙂

Buy a book or video at 50% the price to help Japan

I just wanted to quickly say that O’Reilly has made a very nice gesture by deciding to give away, on a one-day-only special deal, all their books an videos at 50% the price. All proceeds will be donated to the Japanese Red Cross Society.

Please help us raise money for those affected by this horrible natural disaster, by buying books and videos at a great price from O’Reilly. Your help won’t go unrecognized and we will really appreciate it.

Please go here to purchase the goods: http://oreilly.com/store/dd-jpn.html

Many thanks for your support.

Logging in iOS SDK – Ultimate NSLog – Explained Through Video

NSLog in iOS SDK is great. It really is nice but it lacks some fundamentals such as printing out line numbers, class names and etc. In this video you will learn how you can redirect the implementation of NSLog to your own implementation and extend the functionality of NSLog by adding line numbers, class names and etc to its output.

This is the fourth and the final video in the series of videos that I prepared, teaching iOS developers how to take advantage of internals of the SDK in order to make life easier for themselves and those working on the same product as them.

Easter Egg in GarageBand for iPad (Curtain-Call demo song)

So after reading how cool GarageBand was (which it truly is) for iPad, I purchased it the other day. I got a few crashes after using it for a long time. I think some memory warnings, because I am running it on the original iPad rather than iPad 2.

When you open the app, you can start composing music. But what got my attention was that there is a little “secret” demo song that gets shipped with GarageBand for iPad and it’s called Curtain-Call. Why is it secret? Because it won’t appear on your iPad’s GarageBand unless it has crashed at least once!

That sounds weird, doesn’t it. But if you can, get GarageBand to crash once on your iPad. Then open it again and in your library of songs, you should see a new song called Curtain Call, it’s amazing. It looks like Apple has put this as an easter egg in GarageBand (that’s so unlike Apple though). Check out the screen shots that I’ve taken of my GarageBand on iPad. Do you have this song in your GarageBand library on the iPad?

I have also attached the song to the end of this post, if you want to just listen to it. It really sounds cool knowing that it has been composed entirely on an iPad with GarageBand!

Curtain Call, GarageBand Demo Song (Easter Egg)

 

 

Curtain Call 8 Track

Curtain Call iPad Demo Song for Garage Band

Loggin in iOS SDK – More Tips and Tricks and Magic Macros

This is the ultimate debug-killer! This is the third video in the series of videos that I’ve prepared, teaching iOS developers how to take advantage of some of the most awesome features and macros in the iOS SDK in order to completely replace having to debug their code, with the smooth and easy ride of logging.

In this video, you will learn how to print out logs to the console with the exact line number from where the logs are getting printed. You will also learn how to put all the knowledge you’ve learnt from this video and the previous 2 videos in the series, into 3 handy and magical macros that you can use in your iOS projects. Enjoy!

Featured Author?!

I got an email from O’Reilly today. O’Reilly’s newsletter it was…

I saw on the left column that I have been chosen as the featured author for this month’s newsletter. What an honour. I’ve attached a screen shot to this post…

Me as Featured Author on O'Reilly's Newsletter

I have been chosen as O'Reilly's featured author in March 2011