您的位置:首页 > 移动开发 > IOS开发

iOS: Storyboard

2012-03-09 01:39 183 查看
Storyboard tutorial

http://maniacdev.com/ios-5-sdk-tutorial-and-guide/xcode-4-storyboard/
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2

http://kurrytran.blogspot.com/2011/07/simple-ios-5-tutorial-using-storyboard.html

http://codingandcoffee.wordpress.com/2011/10/12/iphone-tutorial-one-introduction-to-storyboarding/

http://www.runpc.com.tw/content/content.aspx?id=108345

Storyboard in XCode 4.2 with Navigation Controller and Tabbar
Controller

/article/8615567.html

/article/8615568.html

Storyboard tutorial video

http://www.youtube.com/watch?v=UdQfR4nsXvI

我的一些笔记

在storyboard里的每个scene里,通常来讲都会包含下列的元素 (First Responder, View Controler, View and Some components):



逐一讲解:

First Responder: The first responder stands for the object that the user is currently interacting with. When a user works with
an iOS application, multipleobjects could potentially respond to the various gestures or keystrokes that theuser creates. The first responder is the object currently in control and interact-ing with the user. A text field that the user is typing into, for
example, wouldbe the first responder until the user moves to another field or control.

View Controller: 用来载入对应的scene并与其进行交互。它会对应一个View

View: 它是UIView的一个实例,用来代表该View controller对应的interface。一个View之间是可以有结构层次的,components看作是uiview
instance的subviews, 而uiview instance则看作是component的superview.

* The Relationship Between Views, Scenes, and Storyboards

如果你认为 "storyboard’s scene" = "a
view",其实不是很确切,应该为“A scene is used to visually describe a view,同时它还references
a corresponding controller for the view”。换句话说:“a
scene is where you go to edit a view and assign a controller to it.”,也就是说一个scene包含一个view和一个对应的view
controller。而storyboard则包含你的project用到的所有scenes!

* 之前版本的Xcode,每个view都会有一个xib
file,而新版本的storyboard则包含所有的views,以及view直接的relationship。你还可以在storyboard里控制view flow。

* Storyboards make working with table views a lot easier with the new prototype cells and static cells features

* storyboard-base app的文件结构以及启动方式和之前Xcode版本的有较大不同。在之前的nib-based
app都会有一个MainWindow.xib file,这个nib file包含the top-level UIWindow object, a reference to the App Delegate, and one or more view controllers。而storyboard-based
app不再使用MainWindow.xib.那么storyboard-base app是怎样启动的呢?

1. 首先看AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate: UIResponder <UIApplicationDelegate>

@property(strong, nonatomic) UIWindow*window;

@end

storyboard-base app要求你的application delegate必须继承UIResponder (而在nib-based
app通常它只是继承NSObject)以及必须有一个UIWindow
property (unlike before, this is not an IBOutlet)

2.然后看AppDelegate.m file.

在nib-base app的appDelegate.m里,会add the main view controller’s view to the window or set the window’s rootViewController property。而在storyboard-base
app的AppDelegate.m,你会看到所有的method都是empty的,即使是application:didFinishLaunchingWithOptions方法都只有一行代码:return
YES。

The AppDelegate.h and AppDelegate.m files make up the delegate for the instanceofUIApplication
that this project will create. In other words, these files can beedited to include methods that govern how the application behaves when it is running.

3. Info.plist file

nib-base app是用"xxx-Info.plist"
file的NSMainNibFile属性or “Main nib file base name”来告诉UIApplication去load
MainWindow.xib and hook it into the app. 而在storyboard-base app,则是用"xxx-Info.plist"
file的UIMainStoryboardFile属性or “Main storyboard file base name”来设置在app启动时哪一个storyboard被载入,UIApplication会load该storyboard,并实例化它的第一个view
controller,然后把其对应的view放到AppDelegate.h定义的UIWindow中。

4. supporting files/main.m file

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc,char *argv[]){

@autoreleasepool{

return UIApplicationMain(argc, argv,nil,

NSStringFromClass([AppDelegate class]));

}

}

nib-base app中的main.m file中UIApplicationMain()的最后一个参数是nil,而在storyboard-base
appUIApplicationMain()的最后一个参数是NSStringFromClass([AppDelegate class]).

A big difference with having a MainWindow.xib is that the app delegate is not part of the storyboard. Because the app delegate is no longer being loaded from a nib (nor from the storyboard), we have to tell UIApplicationMain specifically what the name of our
app delegate class is, otherwise it won’t be able to find it.

view controller container是指能够往里面添加一个或多个view controller的东东. 有4种view
controller container:

* Tab Bar Controller

*Navigation Controller:有一連串的動作要執行,畫面會因此切換甚至有階層性的關係,這個部分就常使用到 Navigation
Controller。navigation controller后面跟着的view
controller的view显示时会带有navigation bar。

ref link: http://blog.sina.com.cn/s/blog_67419c420100qfuo.html
* Split View Controller

* Page View Controller

当你往storyboard drag and drop一个tab bar controller时,它会添加3个scene by default,一个是tab view controller container,另外2个是每个tab的view controller。在tab
bar controller scene里,你会看到多了2个"relationship" items,用来表示会连接2个tab的view controller。

如何在一个view controller前面添加一个navigation
controller?


With the View Controller selected, choose Editor\Embed In\Navigation Controller from Xcode’s menubar.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: