(For more resources related to this topic, see here.)
In this recipe, we will learn how to configure an application's project properties using Xcode so that it is set up correctly to use a storyboard file.
To begin, perform the following simple steps:
In this recipe, we gained an understanding of what storyboards are, as well as how they differ from user interfaces created in the past, whereby a new view would need to be created for each XIB file for your application.
Whether you are creating applications for the iPad or iPhone, each view controller that gets created within your storyboard represents the contents of a single screen, comprised of the contents of more than one scene.
Each object contained within a view controller can be linked to another view controller that implements another scene.
In our final steps, we looked at how to configure our project properties so that it is set up to use the storyboard user interface file by our application.
You can also choose to manually add new Storyboard template to your project. This can be achieved by performing the following simple steps:
- (BOOL)application:(UIApplication *)application didFinishLaunchin gWithOptions:(NSDictionary *)launchOptions { // Override point for customization after // application launch. return YES; }
For more information about using storyboards in your applications, you can refer to the Apple Developer documentation, located at https://developer.apple.com/library/ios/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/InterfaceBuilder/InterfaceBuilder.
In this recipe, we will learn how to create a single view application to build our Twitter application.
In this recipe, we will start by creating our TwitterExample project.
To begin with creating a new Xcode project, perform the following simple steps:
The Company Identifier for your app needs to be unique. Apple recommends that you use the reverse domain style (for example, com.domainName.appName).
Once your project has been created, you will be presented with the Xcode development environment, along with the project files that the template created for you.
In this recipe, we just created an application that contains a storyboard and consists of one view controller, which does not provide any functionality at the moment. In the following recipes, we will look at how we can add functionality to view controllers, create storyboard scenes, and transition between them.
The process of creating scenes involves adding a new view controller to the storyboard, where each view controller is responsible for managing a single scene. A better way to describe scenes would be to think of a movie reel, where each frame that is being displayed is the actual scene that connects onto the next part.
When adding scenes to your storyboard file, you can add controls and views to the view controller's view, just as you would do for an XIB file, and have the ability to configure outlets and actions between your view controllers and its views.
To add a new scene into your storyboard file, perform the following simple steps:
Once you have added the controls to each of the view, your final interface should look something like what is shown in the following screenshot:
The next step is to create the Action event for our Compose Tweet button so that it has the ability to post tweets. To create an action, perform the following steps:
The highlighted line in the following code snippet shows the completed ViewController.h interface file, with our method that will be responsible for calling and displaying our tweet sheet.
// ViewController.h // TwitterExample // // Created by Steven F Daniel on 21/09/12. // Copyright (c) 2012 GenieSoft Studios. All rights reserved. #import
@interface ViewController : UIViewController // Create the action methods - (IBAction)composeTweet:(UIButton *)sender; @end
Now that we have created our scene, buttons, and actions, our next step is to configure the scene, which is shown in the next recipe.
In this recipe, we looked at how we can add a new view controller to our storyboard and then started to add controls to each of our view controllers and customize their properties.
Next, we looked at how we can create an Action event for our Compose Tweet button that will be responsible for responding and executing the associated code behind it to display our tweet sheet.
Instead of us hooking up an event handler to the TouchUpInside event of the button, we decided to simply add an action to it and handle the output of this ourselves. These types of actions are called "instance methods". Here we are basically creating the Action method that will be responsible for allowing the user to compose and send a Twitter message.