UICollectionViewController Tutorial


You can download the source project from here

As you all probably know the UICollectionView control was announced in Apple’s iOS 6.0 beta. Here I’m going to show a very simple example of using this new UI control.
This post doesn’t cover all the abilities of  the collection views but rather illustrates the basic functionality of it.
First of all let’s create a test iPhone application for that. Let it be a “Single View” app with storyboards and using automatic reference counting.


Then you’d better remove the default view controller in storyboard and add CollectionViewController instead of this.



Now it’s required to set up a data source for the collection view. In our case it’ll be the ViewController class which already exists in the application. We should just inherit the ViewController from UICollectionViewController class and specify it in storyboard as a class for added Collection View Controller.


And now we came to the point when we need some test data to be represented in the collection view. For that I’ve prepared a few photos of birds and they are going to be shown in two columns where the item is a thumbnail and a corresponding description.
For these purposes the UICollectionViewCell subclass is needed. So lets add the CollectionViewCell class and specify two outlets there: imageView and label. Then
  • Set up cell’s class in storyboard like it was done for the Collection View
  • Make corresponding changes in cell view by adding an image view and a label
  • And finally connect cell’s outlets.
Also don’t forget please to set the cell’s identifier in storyboard and then use this identifier in code when deque the cell. It might be any string - just @"Cell" in my case.
And one more thing, label has black text color by default the same as collection view’s background color. You should figure this out in some way J.



Now you can add a new class Bird with simply two properties like imageName and birdName for instance and initialize the test data source. This part isn’t described here so detailed because I suppose you know how to do that for sure :)


And at last you need to implement collection view’s data source methods.


Here we are! Now you can launch the application and it should look like below picture.


You can download the source project from here


iPhone development. Intro video.

Did you try to add some intro videos into you iPhone applications? Have you got some problems with it?

I had a bit one concerned with the device orientation.
The whole application was designed for a portrait mode. But when I tried to play animation in the method
- (void)applicationDidFinishLaunching:(UIApplication *)application;
 it was played by default in a landscape mode. I have rotated video immediately after starting but as a result a black square appeared for a second before animation.

So, here comes my solution:

  1. Remove [window makeKeyAndVisible] from applicationDidFinishLaunching.
  2. Add window.hidden = YES before playing the video.
  3. Add [window makeKeyAndVisible] after finishing video processing.
That's all. Thanks.