Using Storyboards

Exclusive offer: get 50% off this eBook here
Xcode 4 Cookbook

Xcode 4 Cookbook — Save 50%

Over 100 recipes to build your own fun and exciting iOS applications with this book and ebook.

$35.99    $18.00
by Steven F Daniel | June 2013 | Cookbooks

Starting with the release of Xcode 4.2 and iOS 5, developers and designers now have the ability to lay out the workflow of their applications using the new storyboards feature that has been incorporated as part of the XIB editor in Xcode.

Instead of creating numerous interface files, you can now start dragging and editing all your views in one place with the ability to specify transitions between screens and the associated actions that trigger them.

In this article by Steven F. Daniel, who has also authored the book Xcode 4 Cookbook, we will be gaining an understanding of what storyboards actually are, and how they require iOS 5 or later, as well as familiarizing ourselves with the new work flow that has been implemented within the XIB editor within Xcode.

(For more resources related to this topic, see here.)

Configuring storyboards for a project

Getting ready

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.

How to do it...

To begin, perform the following simple steps:

  1. Select your project from the project navigator window.
  2. Then, select your project target from under the TARGETS group and select the Summary tab.

  3. Select MainStoryboard from the Main Storyboard drop-down menu, as shown in the preceding screenshot.

How it works...

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.

There's more…

You can also choose to manually add new Storyboard template to your project. This can be achieved by performing the following simple steps:

  1. Select your project from the project navigator window.
  2. Select File New | File…| or press command + N.
  3. Select the Storyboard template from the list of available templates, located under the User Interface subsection within the iOS section.
  4. Click on the Next button to proceed to the next step in the wizard.
  5. Ensure that you have selected iPhone from under the Device Family drop-down menu.
  6. Click on the Next button to proceed to the next step in the wizard.
  7. Specify the name of the storyboard file within the Save As field as the name of the file to be created.
  8. Click on the Create button to save the file to the specified folder.
  9. Finally, when we create our project using storyboards, we will need to modify our application's delegate AppDelegate.m file, as shown in the following code snippet:

    - (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.

Creating a Twitter application

In this recipe, we will learn how to create a single view application to build our Twitter application.

Getting ready

In this recipe, we will start by creating our TwitterExample project.

How to do it...

To begin with creating a new Xcode project, perform the following simple steps:

  1. Launch Xcode from the /Developer/Applications folder.
  2. Select Create a new Xcode project, or click on File | New | Project….
  3. Select Single View Application from the list of available templates.
  4. Click on the Next button to proceed to the next step in the wizard.
  5. Next, enter in TwitterExample as the name of your project.
  6. Select iPhone from under the Devices drop-down menu.
  7. Ensure that the Use Storyboards checkbox has been checked.
  8. Ensure that the Use Automatic Reference Counting checkbox has been checked.
  9. Ensure that the Include Unit Tests checkbox has not been checked.
  10. Click on the Next button to proceed to the next step in the wizard.
  11. Specify the location where you would like to save your project.
  12. Then, click on the Create button to save your project at the specified location.

    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.

How it works...

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.

Creating storyboard scenes

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.

Getting ready

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.

How to do it...

To add a new scene into your storyboard file, perform the following simple steps:

  1. From the project navigator, select the file named MainStoryboard.storyboard.
  2. From Object Library, select and drag a new View Controller object on to the storyboard canvas. This is shown in the following screenshot:

  3. Next, drag a Label control on to the view and change the label's text property to read About Twitter App.
  4. Next, drag a Round Rect Button control on to the view that we will use in a later section to call the calling view. In the button's attributes, change the text to read Go Back.
  5. Next, on the first view controller, drag a Round Rect Button control on to the view. In the button's attributes, change the text to read About Twitter App. This will be used to call the new view that we added in the previous step.
  6. Next, on the first view controller, drag a Round Rect Button control on to the view, underneath the About Twitter App button that we created in the previous step. In the button's attributes, change the text to read Compose Tweet.
  7. Next, save your project by selecting File | Save from the menu bar, or alternatively by pressing command + S.

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:

  1. Open the assistant editor by selecting Navigate | Open In Assistant Editor or by pressing option + command + ,.
  2. Ensure that the ViewController.h interface file gets displayed.
  3. Select the Compose Tweet button; hold down the control key, and drag it from the Compose Tweet button to the ViewController.h interface file between the @interface and @end tags.
  4. Choose Action from the Connection drop-down menu for the connection to be created.
  5. Enter composeTweet for the name of the method to create.
  6. Choose UIButton from the Type drop-down menu for the type of method to create.

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.

How it works...

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.

Xcode 4 Cookbook Over 100 recipes to build your own fun and exciting iOS applications with this book and ebook.
Published: May 2013
eBook Price: $35.99
Book Price: $59.99
See more
Select your format and quantity:

Configuring storyboard scenes

When you want to transition from one view controller to another, you can hold down the control key and click a button, table view cell, or any other object from one view controller, and then drag it to the new view controller for a different scene. This technique of dragging between view controllers creates, what is known as a segue.

A segue is a configurable object that supports all of the same types of transitions made available to you within the UIKit class reference, such as modal transitions and navigation transitions.

Getting ready

You also have the ability to define custom transitions that replace one view controller with another.

How to do it…

In order to see how this can be achieved, we need to modify our TwitterExample application that we created in a previous recipe. Perform the following steps to do so:

  1. Select the About Twitter App (Round Rect Button) control, and then hold down the control key while dragging it to the view controller containing the Go Back button.
  2. Release the mouse button, and then choose the modal option from the Action Segue pop-up menu.

    You will notice that a gray arrow connects both of your view controllers. When the About Twitter App button is pressed, it will display the page containing the Go Back button.

  3. Next, we need to do the same for our second view, so that when the Go Back button is pressed, it will return back to our first view.
  4. Repeat steps 1 to 2, but substitute the Go Back button for the About Twitter App button.

Explanations of the storyboard segues that come part of Xcode 4 are included in the following table:

Segue name

Description

modal

 

A modal view controller is not a specific subclass of the UIViewController class, as any type of view controller can be presented modally by your application. However, like the tab bar and navigation view controllers, you can present your view controllers modally when you want to convey a specific meaning about the relationship between the previous view hierarchy and the newly presented view hierarchy.

 

push

 

The push segues allow you to push a new view controller onto the navigation stack, just as if you were stacking plates. The view at the top of the stack being the one that gets rendered.

These allow you to customize and call a view controller from code using the prepareForSegue method, and are what you use to present the content of your application.

custom

 

The job of the view controller is to manage the presentation of some content and coordinate the update and the synchronization of that content with the application's underlying data objects.

In the case of a custom view controller, this involves creating a view to present the content and implementing the infrastructure needed to synchronize the contents of that view with your application's data structures.

Once you have done this, your view controllers should look like something shown in the following screenshot. You can apply a number of transitions to each of your view controllers, so that they can perform animation when they get displayed to the view.

To learn how to apply transitions to your view controller, please refer to the Applying transitions to storyboards recipe on Transitions in this article.

Now that you have applied each of the segues to both view controllers, our final step is to compile, build, and run our application.

From the Product menu, select Run. Alternatively, you can press the command + R keys to compile, build, and run the application.

The following screenshot shows our application running within the iOS Simulator, with each of their associated screens displayed:

How it works...

So there you have it. In this recipe, we have learned how to create and add new scenes into our main storyboard, as well as the process on how we are able to link these up and configure each scene when a button has been pressed through the use of segues.

There is also another way in which we can transition to scenes within our storyboard through a programmatic approach. We will be taking a closer look into this, when we embark on the Presenting storyboard view controllers programmatically recipe in this article.

Applying transitions to storyboards

In this recipe, we will look at how we can apply transition animations to views as well as each of the available transitions that come with storyboards.

Getting ready

You may have seen such transitions in applications, such as the photos app that comes as part of the iPhone and iPad, where you can apply a transition and start a slideshow.

How to do it…

In order to configure a segue to specify a kind of transition to use between the different scenes, perform the following simple steps:

  1. Click on the segue link for the first view controller as indicated by the large circle in the following screenshot.
  2. Click on Attributes Inspector and then click on the Transitions drop-down menu.

You have the ability to choose from the various transition types that are only applicable to the Modal style; these are explained within the following table:

Transition name

Description

Default

 

When this transition is selected, it uses the Cover Vertical transition style.

 

Cover Vertical

 

When the view controller is presented, its view slides up from the bottom of the screen. When the view is dismissed, it slides back down.

 

Flip Horizontal

 

When the view controller is presented, the current view initiates a horizontal 3D flip from right to left-hand side, resulting in the revealing of the new view as if it were on the back of the previous view. When this view is dismissed, the flip occurs from left to right-hand side, returning to the original view.

 

Cross Dissolve

 

When the view controller is presented, the current view fades out while the new view fades in at the same time. When the view is dismissed, a similar type of cross-fade is used to return to the original view.

 

Partial Curl

 

When the view controller is presented, one corner of the current view curls up to reveal the modal view underneath. When the view is dismissed, the curled up page uncurls itself back on top of the modal view. A modal view presented using this transition is itself prevented from presenting any additional modal views.

This transition style is supported only if the parent view controller is presenting a full-screen view and you use the UIModalPresentationFullScreen modal presentation style. Attempting to use a different form factor for the parent view or a different presentation style triggers an exception.

These transitions come as part of the UIViewController class that inherits from the UIKit framework. The UIViewController class provides the underlying fundamental viewmanagement model for all of your iOS apps.

For more information on the preceding transition types, refer to the UIViewController framework reference in the Apple Developer documentation, located at https://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html.

How it works...

Xcode provides the option of changing the visual appearance of the transition as it takes place from one scene to another within a storyboard. These are commonly referred to as segues.

Using transitions enables you to apply a variety of different styles to each of your view controllers that are to be rendered and displayed to the view, and are represented by arrows between each of the view controllers. By default, a Cover Vertical transition is performed whereby the new scene slides vertically upwards from the bottom of the view to cover the currently displayed scene.

You have the ability to define custom transitions that enable you to provide a custom segue class method to handle the transition. This can be achieved by selecting custom for the style of a segue, and fill in the name of the custom segue class to use. If you want to use any of the standard segue classes, you can find these located within the UIKit class.

For information on the standard segue classes, you can refer to the UIKitframework reference in the Apple Developer documentation, located at https://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html.

Composing a tweet

In this recipe, we will look at how we can use the Twitter APIs for iOS 5 and interact with them effectively.

Getting ready

Twitter has provided us with some very simple APIs to follow, making it a snap to interact with them. In this recipe, we will look at how we can use these to post a tweet using the Twitter composition sheet.

How to do it…

In order to use Twitter within your application, we need to add the Twitter framework to your project. This can be achieved by performing the following simple steps:

  1. Select your project from within the project navigator.
  2. Then, select your project target from under the TARGETS group.
  3. Select the Build Phases tab.
  4. Expand the Link Binary with Libraries disclosure triangle.
  5. Click on the + button and select Twitter.framework from the list.
  6. Finally, click on the Add button to add the framework to your project.

Our next step is to create the code functionality that will be responsible for posting our tweet to Twitter:

  1. Open the ViewController.m implementation file from the project navigator.
  2. Type in the following import statements:

    #import <Twitter/Twitter.h>

  3. Next, modify the composeTweet method, as shown in the following code snippet:

    - (IBAction)composeTweet:(id)sender { TWTweetComposeViewController *myTwitter = [[TWTweetComposeViewController alloc] init]; BOOL isSUCCESS = TWTweetComposeViewController.canSendTweet; if (isSUCCESS == YES) { [myTwitter setInitialText:@"Welcome to Twitter API."]; [self presentModalViewController:myTwitter animated:YES]; // Retrieve the result of the Twitter handler to // determine if the message was successfully sent. myTwitter.completionHandler = ^(TWTweetComposeViewControllerResult res) { if (res == TWTweetComposeViewControllerResultDone) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Your tweet was posted successfully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [self dismissModalViewControllerAnimated:YES]; } else if (res == TWTweetComposeViewControllerResultCancelled) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Tweet not posted." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [self dismissModalViewControllerAnimated:YES]; } }; } }

Xcode 4 Cookbook Over 100 recipes to build your own fun and exciting iOS applications with this book and ebook.
Published: May 2013
eBook Price: $35.99
Book Price: $59.99
See more
Select your format and quantity:

How it works...

Starting with iOS 5, whenever you want to compose a Twitter message for submission, you will need to use the TWTweetComposeViewController class instance. The TWTweetComposeViewController class handles everything, and presents us with a tweet composition sheet, so that we can begin to type in our tweet.

The TWTweetComposeViewController class also enables you to set the initial Twitter text information to use, including how to go about adding images and URLs. Next, we declared a myTwitter variable to point to an instance of our TWTweetComposeViewController class.

We then used the canSendTweet class method of the TWTweetComposeViewController class to check to see if the user has correctly installed and set up Twitter. If this has not been done, this statement will fail, and a value of NO (or FALSE) will be returned to the isSuccess variable.

Next, we assigned some text to appear on our composition sheet, by setting the setInitialText method, and then displayed this to the view. Finally, we set up a handler, using the completionHandler method to notify us when the user has completed composing the tweet and display the relevant alert message based on the outcome returned by the method.

For more information on the TWTweetComposeViewController class, you can refer to the Twitter framework reference documentation, located at https://developer.apple.com/library/ios/#documentation/Twitter/Reference/TWTweetSheetViewControllerClassRef/Reference/Reference.html.

There's more…

With the release of iOS 6, integration of social networks is performed through the use of the UIActivityViewController class, or the classes that are contained with the new social framework of the iOS 6 SDK. For general-purpose social networking integration, the UIActivityViewController class is the recommended path.

When using this class, the user is presented with a screen providing a choice of social network services. Once the application has selected a target service, the class then presents the user with a blank message preview panel where the message can be reviewed and then posted.

Next, we will take a look at both the UIActivityViewController and SLComposeViewController classes to see each of their differences.

Using the UIActivityViewController class

The UIActivityViewController class is instantiated from within an application at the point when posting is ready to be made to a social network. The following code snippet shows how to use the UIActivityViewController class to handle posts to Twitter:

NSString *postText = @"My first Twitter Post from iOS 6"; NSArray *activityItems = @[postText]; UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; [self presentViewController:activityController animated:YES completion:nil];

The preceding code snippet instantiates a new UIActivityViewController instance, and passes the text to be included within the dialog box when it is presented to the user. There is an option to include an image with the post, which we will be taking a look at a bit later.

Once the user decides to take an action to post an update from within an application, the following screen is displayed:

Once a destination social network has been selected from the list of choices, a preview sheet will be displayed. In the event that the user has not yet configured an account for the selected social network in the Settings application, a dialog box will appear providing the user to either set up an account or simply cancel the posting.

For more information on the UIActivityViewController class, you can refer to the Apple Developer reference documentation, located at https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivityViewController_Class/Reference/Reference.html.

Using the SLComposeViewController class

In order to use the SLComposeViewController class, a number of steps are required to be performed. First, we need to verify whether the message can be sent to the specific social network service to ensure that the device has been properly configured to use the particular service.

This is achieved by passing through the type of service as an argument to the isAvailableForserviceType method, as shown in the following code snippet:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeT witter]) { // Device has been set up to use Twitter }

The isAvailableForServiceType method accepts the following parameters:

  • SLServiceTypeFacebook
  • SLServiceTypeTwitter
  • SLServiceTypeSinaWeibo

The next step is to create an instance of the SLComposeViewController class and supply an optional completion handler to be called when the compose sheet is either cancelled by the user or used to send a message. Finally, when the message is ready to be presented to the user, the SLComposeViewController object is presented modally by calling the presentViewController method of the parent view controller.

The following code snippet shows how to configure and present the SLComposeViewController class instance for posting to Twitter:

SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [composeController setInitialText:@"Posting using Twitter"]; [composeController addURL: [NSURL URLWithString: @"http://www.packtpub.com/xcode-4-cookbook/book/"]]; [self presentViewController:composeController animated:YES completion:nil];

The preceding code snippet presents you with the Twitter compose sheet with the default text preconfigured using the method calls. The completion handler can be set up to pass a value back, indicating the action taken by the user within the compose sheet view. These values are explained in the following table:

Compose sheet values

Description

SLComposeViewControllerResultCancelled

 

The user cancelled the composition session by touching the Cancel button.

 

SLComposeViewControllerResultDone

 

The user sent the composed message by touching the Sent button.

 

The social framework class that comes with iOS 6 contains two classes that have been designed to provide more flexibility around social networking integration.

The SLComposeViewController class, unlike the UIActivityViewController class, allows you to post a message to a specific social network service within the application code, without requiring the user to make a selection from the list of available services.

The user is then presented with a preview sheet appropriate to the specific service the application has been set up for. Using the social framework within your application is very simple, and can be achieved by performing the following simple steps:

  1. Add Social.framework into your project similarly as we did with Twitter.framework.
  2. Open the ViewController.m implementation file from the project navigator.
  3. Type in the following import statement:

    #import <Social/Social.h>

  4. Next, modify the composeTweet method, as shown in the following code snippet:

    - (IBAction)composeTweet:(id)sender { if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { // Device is able to send a Twitter message SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; SLComposeViewControllerCompletionHandler __block myHandler = ^(SLComposeViewControllerResult result) { if (result == SLComposeViewControllerResultDone) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter" message:@"Yourtweet was posted successfully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } else if (result == SLComposeViewControllerResultCancelled) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter" message:@"Your Tweet was not posted." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } [composeController dismissViewControllerAnimated:YES completion:nil]; }; [composeController setCompletionHandler:myHandler]; [composeController setInitialText:@"Welcome to iOS 6"]; [composeController addURL: [NSURL URLWithString: @"http://www.packtpub.com/xcode-4-cookbook/book/"]]; [self presentViewController:composeController animated:YES completion:nil]; } }

For more information on the SLComposeViewController class, you can refer to the Apple Developer reference documentation, located at https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html.

Adding photos to a tweet

In this recipe, we will learn how we can incorporate images within Twitter messages.

Getting ready

In this recipe, we will look at how we can add an image to a tweet using the Twitter composition sheet.

How to do it…

Adding images to a Twitter message is very easy and can be achieved by performing the following simple steps inside the TwitterExample project:

  1. Open the ViewController.m implementation file from the project navigator.
  2. Next, modify the composeTweet method and add the highlighted code within the following code snippet:

    - (IBAction) composeTweet: (UIButton *) sender { // Attach an image to our Tweet TWTweetComposeViewController *myTwitter = [[TWTweetComposeViewController alloc] init]; [myTwitter addImage:[UIImage imageNamed:@"Blue-Aqua- Apple.png"]]; [self presentModalViewController:myTwitteranimated:YES]; }

In this code snippet, we declare a myTwitter variable to an instance of our TWTweetComposeViewController class. We then use the addImageinstance method, to add an image to the tweet, and then present the view along with the image to the user. Whenever you want to add images to a Twitter message for submission, you will need to use the TWTweetComposeViewController class instance. This class handles everything required, and presents us with a tweet composition sheet, so that we can add images and URLs.

Now that we have added in the final piece of code to our TwitterExample application, first we need to configure our Twitter account information prior to building and running the application. Perform the following steps to set up and configure Twitter:

  1. Open the Settings application from the iOS home screen.
  2. Select the Twitter option from the Settings menu.
  3. Enter your username and password credentials, and click on the Sign In button. If you do not have a Twitter account, you can create one from this screen by selecting the Create New Account option.

  4. Next, build and run the application by selecting Product Run| from the Product menu, or alternatively by pressing command + R.

When the compilation completes, the iOS Simulator will appear, showing our Twitter application.

When you start composing your tweet, you can choose to have your current geographical location added to your message. This feature basically uses the Google Maps API to send your location along with the tweet, and then allowing others to view the precise location on Google Maps.

Attachments can also be added to the composed message, and this can be any valid image (PNG, JPG, and so on).

Clicking on the Send button will submit the message to your Twitter account, and you will receive a message stating that the tweet has been successfully posted.

How it works...

In this recipe, we looked at how we can integrate Twitter-like functionality into our applications. There are many ways in which applications can be more social, by including Twitter. For example, you could make the application auto-tweet, when you unlock a special item within your game, or when you finish the game, or just want to upload your high-score achievements.

This lets all of their friends know they are playing your game, which in turn, gets you more exposure. Another example could be a business application, which could allow the user to tweet the number of successful projects that they have completed. With Twitter getting so much attention lately, you would be crazy to not include some sort of Twitter integration into your own iOS applications.

There's more...

Adding an image to a tweet using the SLComposeViewController class can be achieved by adopting the following code snippet:

// Device is able to send a Twitter message SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [composeController setInitialText:@" My first Twitter Post from iOS 6"]; [composeController addImage: [UIImage imageNamed:@"Blue-Aqua-Apple.png"]]; [composeController addURL: [NSURL URLWithString: @"http://www.packtpub.com/xcode-4-cookbook/book/"]]; [self presentViewController:composeController animated:YES completion:nil];

In the preceding code snippet, we used the SLComposeViewController method to configure and present the tweet composition sheet. We then configured our composer view using the method calls for displaying default text and setting the default image.

Summary

In this article, we learned about storyboards and the different features of story board along with it. We also learned about Tweet applications.

Resources for Article :


Further resources on this subject:


About the Author :


Steven F Daniel

Steven F. Daniel is originally from London, England, but lives in Australia.

He is the owner and founder of GENIESOFT STUDIOS (http://www.geniesoftstudios.com/), a software development company based in Melbourne, Victoria, that currently develops games and business applications for the iOS, Android, and Windows platforms.

Steven is an experienced software developer with more than 13 years of experience developing desktop and web-based applications for a number of companies including, insurance, banking and finance, oil and gas, and local and state government.

Steven is always interested in emerging technologies, and is a member of the SQL Server Special Interest Group (SQLSIG) and the Java Community. He has been the co-founder and Chief Technology Officer (CTO) of SoftMpire Pty Ltd., a company that focused primarily on developing business applications for the iOS and Android platforms.

He is the author of Xcode 4 iOS Development Beginner's Guide, iOS 5 Essentials, and iPad Enterprise Application Development Blueprints.

You can check out his blog at http://geniesoftstudios.com/blog/, or follow him on twitter at http://twitter.com/GenieSoftStudio.

Books From Packt


 Unity iOS Game Development Beginners Guide
Unity iOS Game Development Beginners Guide

Flash iOS Apps Cookbook
Flash iOS Apps Cookbook

 Unity iOS Essentials
Unity iOS Essentials

UDK iOS Game Development Beginner's Guide
UDK iOS Game Development Beginner's Guide

iOS Development using MonoTouch Cookbook
iOS Development using MonoTouch Cookbook

iOS 5 Essentials
iOS 5 Essentials

iPhone Location Aware Apps by Example - Beginner's Guide
iPhone Location Aware Apps by Example - Beginner's Guide

Xcode 4 iOS Development Beginner's Guide
Xcode 4 iOS Development Beginner's Guide


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software