Last updated by at .

iOS Programming Recipe 14: Implementing A UICollectionViewController

UICollectionView is great for displaying information in a grid or other custom layouts. In iOS 6 you’ll see collection views most likely used in many apps such as the podcasts app for viewing different podcasts. Since in most cases you’ll want to use UICollectionViewController, we’ll focus on that for this recipe.

Assumptions

  • You are familiar with Xcode and setting up a single view controller. If not check out our recipe on Xcode first.

Setting Up The View

Go ahead and create a new single view controller project. I titled mine “CollectioViewFun”. When the project opens up, You’ll want to delete the single view controller from the storyboard and drag a new collection view controller in it’s place. This should look like the following:

CollectionViewController

Now since our class type has changed from a standard view controller to a collection view controller we’ll want to change the class type in the viewController.h file as well. Go ahead and change the class name from ViewController to CollectionViewController as well. Don’t forget to change all instances of the term “ViewController” in both the .m and .h files:

[Read more…]

iOS Programming Recipe 11: Using The UITableView Part II

In Part I of this recipe we left off with a UITableView that Displayed some creatures which were grouped by type. In this Recipe we’ll be extending the functionality a bit and emplement a delegate in order to handle a touch event. In addition, we’ll take a minute to explore styling of the table view and cells.

Assumptions

  • You Have already read through Part I, if not read through that first.

Styling The Table View

The next two sections will be brief, but I thought it was worth visiting since there are a few things that can be done right from the property inspector.

First of choose the tableview object from the storyboard and go to the property inspector tab on the top right hand pane. Choose Grouped from style section and go ahead and change default to some color, I change mine to blue.

[Read more…]

iOS Programming Recipe 11: Using The UITableView Part I

In most apps you’re sure to find a table view whenever a list of items needs to be presented. UITableView, similar to UIPickerView, declares both a data source and delegate protocol. The data source protocol is required while the delegate is optional. We’ll need to make use of the data source protocol for the UITableView class. For this recipe I chose to show a table view with bugs and animals shown. The bugs and animals will have seperate sections.

Assumptions

  • You are familiar with Xcode, if not familiarize yourself here.

Setting Up the View

First start with a single view controller project. Now drag a UITableView object onto the existing view from the object library and then drag a UITableViewCell onto the newly created table view. When you’re done you should have something that looks like this:

[Read more…]

iOS Programming Recipe 7: Using the UIPickerView

The UIPickerView can be a frustrating element for a new iOS programmer. I know first hand as I was just recently there.

For this example I’m going to create a simple color picker. from the picker we can select a color and the RGB value will print to the screen. Seems easy enough? right? Let’s get to it!

Assumptions

  • You Are familiar with Xcode and the storyboard
  • you know how to create a single view controller

Setting up the Storyboard

First start out with a single view controller and title it whatever you like. I titled mine “PickIt”.

From the Storyboard drag a new UIPickerView object on to the view from the Object Library in the bottom right hand corner of the screen.

Create some new labels titled “Color Picker”, “You Chose:”, and “Nothing”. Arrange all of these elements as seen on the scren below. Optionally you can choose a background for your view too.

[Read more…]

iOS Programming Recipe 5: Passing Values Between Segues with PrepareForSegue

In Part 1 and 2 of Recipe 3 I stepped through creating a modal relationship using storyboards. There was no code needed to make this relationship using storyboards. If you want to pass information from the presenting view to the presented view you’ll need to add some code.

Assumptions

  • You know how to set up a segue relationship using the storyboard. If not go read part 1 and 2 of Recipe 3 here: Part 1Part 2

Setting Up the Views

To start off, I created a new single view controller project and replaced the view controller with a navigation view controller. Then I deleted the root controller and added two new view controllers. I made one view controller the root view controller, and I didn’t setup the segue on the other controller for now. Then I gave each views the titles “Root View Controller” and “First View Controller” respectively. See recipe 3 for more details on setting this up.

Next I deleted the viewController class and all of it’s refferences. Delete the viewController.m file and viewController.h file and Xcode will ask you if you would like to remove the refferences.

Next we’ll need to create two new UIViewController Classes. To do this push the plus sign in the bottom left hand corner of the project navigator.

Create New UIViewController Classes

When prompted choose objective-C class under Cocoa Touch and press next. For the next prompt name the Class “RootViewController” and choose the subclass “UIViewController” then press next. You will then press create on the next prompt. Repeat this step and name the next class “FirstViewController”.

Choosing UIViewController subclass

When you’re done creating classes you should see the newly created .m and .h files in the project navigator.

New Project Navigator

 

The last thing we’ll want to do is connect our new classes to our views on the storyboard. To do this, select the view and in the utilities pane under the identity inspector choose the class from the dropdown.  Do this for both the RootViewController and the FirstViewController.

[Read more…]

css.php
Privacy Policy