Storyboarding is an excellent feature introduced in iOS 5. Save time creating user interfaces for the app.
If your app has multiple screens storyboards can help you reduce the glue level of your code. For example, from one screen to another screen. A separate nib file is not used for each view controller. Your app will use only one storyboard to include all of these view controllers designs and relationships.
Storyboard has many advantages:
You can have a better conceptual overview of the screens in all apps and the relationships between them. It's easier to keep track of everything because the entire design is in a separate file. Instead of dividing it into multiple separate nib files.
Storyboard describes the transmission between different screens. These transports are called segues and can be established by simply ctrl-dragging from one view controller to another. Because the presence of segues reduces the amount of code
Storyboard makes the table view design and use more convenient. Contains the cels and static sells features and properties.
You can also talk about mixing storyboard and nib files
storyboards Tutorial:ios 7 style
Open Xcode to create a new project, using the single view Applicaiton template.
and fill in the following options
- Product Name: ratings
- Organization Name:fill this in however
- Company Identifier:the Identifier So you use for your apps, in reverse domain notation
- Class Prefix:leave This empty
- Devices: iPhone
Previous versions of Xcode need to specifically indicate whether to use storyboards, but XCODE5 no longer has this option, storyboards is available by default.
After the creation is done, it looks like this:
The new project has two class,appdelegate and Viewcontroller. Main.storyboard file and no nib file
This is a vertical display only support app, so need to Deployment Info, Device Orientation below uncheck Landscape left and Landscape right options
Open the Main.storyboard file, only one scene is visible on the iphone at a time, but you can display multiple times in the ipad, such as Master and detail panes or popover content
Note: Xcode 5 enables Auto Layout by default for storyboard and nib files. Auto Layout is a cool new technology for making flexible user interfaces that can easily resize, which are useful on the IP AD and for supporting the larger IPhone 5, but it's only works on IOS 6 and up. It also has a bit of a learning curve, and which is the why do you ' re not using it in this tutorial. To learn more on Auto Layout, see our Books iOS 6 by Tutorials and iOS 7 by tutorials.
The dock shows the top-level objects in this scene. Each scene has at least one view controller object, a first Responder object, and an exit item. However, other top-level objects can be implied. The dock is easy to use connections to outlets and actions. If you need to connect to a view controller, you can try simply drag his icon in the dock.
Note: You probably won ' t is using the first Responder very much. This is a proxy object, refers to whatever object with first responder status at any given time. It is also present in your nibs and you probably never had a need to use it then either. As an example, you can hook up the Touch up Inside event from a button to first Responder ' s cut:selector. If at some point a text field have input focus then you can press that button to make the Text field, which are now the Firs T responder, cut its text to the pasteboard.
If you've used the nib app before, there will always be a mainwindow.xib file. This nib file contains the top-level UIWindow object. A reference to an app delegate and one or more view controllers. When you use storyboard to include your app UI, Mainwindow.xib isno longer used. So how is storyboard loaded by the app?
Application proxy, open AppDelegate.h can see:
This is a requirement for using storyboards, your application delegate need to inherit from Uiresponder and have a UIWindow attribute. If you look at APPDELEGATE.M, you'll see nothing at all. The secret is in the ratings-info.plist file .
The storyboards app uses UIMainStoryboardFile the keyword or main storyboard file base name to specify the storyboard name that must be loaded when the app starts.
When this is set, UIApplication automatically initializes the first view controller in the storyboard when the storyboard file is loaded, and then puts its views into a new UIWindow object. These don't have to write your own code. This can also be seen in deployment info in the Project Settings window.
In the main.m file,
App delegate is not part of storyboard. You must pass the name of the app delegate class to Uiapplicationmain (), otherwise you won't be able to find it.
Just Add It to My Tab
The rating app has a tabbed interface containing two screens. It's very easy to create this tabs with storyboard.
Open Main.storyboard, and drag and drop a tab Bar controller with two view controllers included.
Two view controllers each corresponding one tab. Uitabbarcontroller is called Container View controller because it contains one or more view controllers.
The container relationship is represented by the arrows between the tab Bar controller and the view controllers.
Note: If you want to move the Tab Bar Controller and its attached view controllers as a group, can I?-click to Select multiple scenes and then move them around together. (Selected scenes has a thick blue outline.)
Drag a label into the first view controller and sets the text to "primary tab". and drag a label to the second view controller and name it "Second tab."
Select the tab controller and enter Attributes Inspector to tick box "is Initial View controller".
This time you will find that the arrow pointing to the regular view controller points to the TAB bar Controller
This means that when you start the app, UIApplication will say the tab bar controller is included in main screen. Storyboard always has a separate view controller that is designed to be initial view controller, the entry point for storyboard
Tip: The initial view controller, you can also drag the arrow between view controllers. You can also drag arrows to specify initial view controller
Effects after running the app:
Note: If you connect more than five scenes to the tab-Bar Controller, it automatically gets a more ... Tab when you run the app. Pr Etty neat!
If you connect more than 5 screens to the tab bar controller, it will automatically get a more tab, very dexterous
Adding a Table View Controller
The two windows that are connected to the tab bar Controller are regular uiviewcontrollers. You will replace the first tab with Uitableviewcontroller
Select the first view controller and delete it. Drag a table View controller.
Select the table View controller, and then select Editor\embed in\navigation Controller in the menu bar above Xcode. This will add another view controller
Of course you can also drag a navigation controller from the library, but this is more convenient.
Because the navigation controller is also a container view controller, it also has a relationship arrow pointing to the table view Controller. You can view these relationships in document outline.
Note that the table View controller now has a navigation bar. Interface Builder does it automatically.
Let's connect these two windows to the tab bar Controller. Ctrl-drag from the tab bar controller to the Navigaiton controller. A small window POPs menu will appear.
Choose Relationship Segue–view Controllers, which creates a new relationship between these two windows.
Storyboards Tutorial 01