转换到 StoryBoard 的公布说明(Converting to Storyboards Release Notes)

太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的漂亮人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

转换到 StoryBoard 的公布说明(Converting to Storyboards Release Notes)

Storyboarding 是一种新的方式用于创建 iOS 应用的用户界面。从 iOS 5 和 Xcode 4.2 開始引入。使用 storyboard,你能够把组成你的应用的视图控制器设计成 Xcode 设计画布中的场景。而且使用 segue 在场景间可视化地定义导航。

Storyboarding is a new way to create user interfaces for iOS applications, beginning with iOS 5 and Xcode 4.2. Using storyboards, you can design the view controllers that compose your application as scenes in the Xcode design canvas and visually define the navigation between the scenes using segues.

把一个已有的 iOS 应用转换成使用 storyboard 须要採取一些步骤。另外。有一些其他模式能够採用。

There are a few steps you need to take to convert an existing iOS application project to use storyboards. In addition, there are other new patterns you can adopt.

内容例如以下:

Contents:

  • 配置应用代理
    Configure the Application Delegate
  • 加入 Storyboard 到project
    Add a Storyboard to the Project
  • 为project设置主 Storyboard
    Set the Main Storyboard for the Project
  • 訪问第一个视图控制器
    Accessing the First View Controller
  • 配置表视图
    Configuring Table Views



配置应用代理
Configure the Application Delegate


应用代理负责载入 storyboard 并管理窗体。你须要在 UIApplicationMain 中指定应用代理类的名称,并确保应用代理有一个叫 window 的属性。

The application delegate is responsible for loading the storyboard and managing the window. You need to specify the name of the application delegate class in UIApplicationMain, and ensure that the application delegate has a property called window.

假设你没有应用代理类,那么须要创建一个。一个最小实现会像这样:

If you don’t have an existing application delegate class, you need to create one. A minimal implementation would look like this:


Listing 1-1 最小应用代理头文件 
Listing 1-1 Minimal application delegate header file

#import <UIKit/UIKit.h>

@interface AppDelegate : NSObject <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end


Listing 1-2 最小应用代理实现文件
Listing 1-2  Minimal application delegate implementation file

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;

@end


注意: 在当前的 Xcode 模板中,应用代理类继承自 UIResponder.。

这样应用代理实例能够參与到 响应链 (responder chain) 以便处理应用层动作。假设你已存在的应用中未使用这种模式,就没有必须为 storyboard 採纳它。

Note: In the current Xcode templates, the application delegate class inherits from UIResponder. This is so that the delegate instance can participate in the responder chain and so handle application-level actions. If you haven’t made use of this pattern in an existing application, there’s no need to adopt it for storyboards.

在 main.m 文件里 UIApplicationMain 类里设置应用代理。

In the main.m file, set the application delegate class in UIApplicationMain.

已有的 main.m 文件可能看起来像是这样:

Your existing main.m file probably looks something like this:

#import <UIKit/UIKit.h>

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

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

int retVal = UIApplicationMain(argc, argv, nil, nil);

[pool release];

return retVal;

}

把它改成这样:

Change it to look like this:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

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

@autoreleasepool {

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

}

}

(将 “AppDelegate” 替换为你的应用代理类的名字).

(replace “AppDelegate” with the name of your application delegate class).

注意: @autoreleasepool 是一个新的 Objective-C 语句用于管理自己主动释放池;它可用于全部 Objective-C 模式。而且比使用 NSAutoReleasePool 类更高效(參看 迁移到 ARC 的公布说明(Transitioning to ARC Release Notes))。

Note: @autoreleasepool is a new Objective-C statement for managing autorelease pools; it is available in all Objective-C modes, and is more efficient than using the NSAutoReleasePool class (see Transitioning to ARC Release Notes).

加入 Storyboard 到project中
Add a Storyboard to the Project

加入一个新的 storyboard 到project中。

按惯例,初始 storyboard 命名为 MainStoryboard 。

Add a new storyboard file to the project. By convention, the initial storyboard is named MainStoryboard.

从对象库中加入第一个视图控制器到 storyboard。你应该会看一个无源的 segue。它指示这是第一个场景。

Add your first view controller to the storyboard from the Object library. You should see a sourceless segue indicating that this is the first scene.

假设第一个视图控制器嵌入在诸如导航控制器或分页控制器这种容器中,那么使用 Editor > Embed In 来正确地嵌入它。

无源 segue 如今应该指向容器视图控制器了。

If the first view controller is embedded in a container such as a navigation controller or tab bar controller, then use Editor > Embed In to embed it appropriately. The sourceless segue should now point to the container view controller:

为项目设置主 Storyboard
Set the Main Storyboard for the Project

In the Summary for application Target, set the value of the Main Storyboard to the name of the storyboard file you created. If there is a value for Main Interface (to specify the first nib file), make sure you remove it.

訪问第一个视图控制器
Accessing the First View Controller

The application delegate is not represented in the storyboard. If you need to access the first view controller (for example, if you are creating a Core Data application and want to pass the delegate’s managed object context to the first view controller), you can do so via the window’s rootViewController. If the root view controller is a container controller—such as an instance of UINavigationController—then you can access your view controller using the appropriate accessor for the container’s contents, for example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

UINavigationController *rootNavigationController = (UINavigationController *)self.window.rootViewController;

MyViewController *myViewController = (MyViewController *)[rootNavigationController topViewController];

// Configure myViewController.

return YES;

}

配置表视图
Configuring Table Views

There are several new ways of working with table views when you use storyboards.

  • The dequeueReusableCellWithIdentifier: method is guaranteed to return a cell (provided that you have defined a cell with the given identifier). Thus there is no need to use the “check the return value of the method” pattern as was the case in the previous typical implementation of tableView:cellForRowAtIndexPath:. Instead of:
  • UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  • if (cell == nil) {
  • cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  • }
  • // Configure and return the cell.
  • you would now write just:
  • UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  • // Configure and return the cell.
  • You can configure table view cells directly in the table view. By default, the prototype cell style is set to Custom, so that you can design your own cell. You can also set the style to one of the built-in UITableViewCell cell styles by using the Attributes Inspector.
  • For a table view that is the view of a UITableViewController instance, you can configure static content directly in the storyboard. In the Attributes Inspector, set the content of the table view to Static Cells. 
    If you use static cells, you can connect outlets from the table view controller to individual cells so that you can configure the cell’s content at runtime.
  • // Declare properties for the outlets.
  • @property (nonatomic, weak) IBOutlet UITableViewCell *firstGroupFirstRowCell;
  • // Configure cells directly.
  • firstGroupFirstRowCell.detailTextLabel.text = newTextValue;

Copyright © 2014 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2011-10-12

转换到 StoryBoard 的公布说明(Converting to Storyboards Release Notes)的更多相关文章

  1. web.confgi转换,web发布时发布配置(debug/release)生成不同的配置文件

    在web.config下有两个config文件,分比为:web.debug.config和web.replease.config文件,打开之后可以看到demo,根据demo修改后即可在发布时根据选择的 ...

  2. ArcGIS中的坐标系定义与转换 (转载)

    原文:ArcGIS中的坐标系定义与转换 (转载) 1.基准面概念:  GIS中的坐标系定义由基准面和地图投影两组参数确定,而基准面的定义则由特定椭球体及其对应的转换参数确定,因此欲正确定义GIS系统坐 ...

  3. GIS中的坐标系定义与转换

    GIS中的坐标系定义与转换 青岛海洋地质研究所 戴勤奋 2002-3-27 14:22:47 ----------------------------------------------------- ...

  4. iOS Foundation 框架概述文档:常量、数据类型、框架、函数、公布声明

    iOS Foundation 框架概述文档:常量.数据类型.框架.函数.公布声明 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业 ...

  5. ios项目里扒出来的json文件

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

  6. Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)

    下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...

  7. iOS-旧项目中手动内存管理(MRC)转ARC

    在ARC之前,iOS内存管理无论对资深级还是菜鸟级开发者来说都是一件很头疼的事.我参 加过几个使用手动内存管理的项目,印象最深刻的是一个地图类应用,由于应用本身就非常耗内存,当时为了解决内存泄露问题, ...

  8. 对Xcode菜单选项的详细探索(干货)

    本文调研Xcode的版本是 7.1,基本是探索了菜单的每一个按钮.虽然从xcode4一直用到了xcode7,但是一般都只是用了一些基础的功能,说来也惭愧.在一次偶然的机遇突然发现了“显示调用层级”的选 ...

  9. 坐标系统与投影变换及在ArcGIS桌面产品中的应用

    坐标系统与投影变换及在ArcGIS桌面产品中的应用 1.地球椭球体(Ellipsoid) 2.大地基准面(Geodetic datum) 3.投影坐标系统(Projected Coordinate S ...

随机推荐

  1. HDU 1213(并查集)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. 冒泡排序 Exercise07_18

    import java.util.Arrays; import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年12月 * 题目:冒泡排序 * */ pu ...

  3. web前端开发必备压缩工具整理

    影响网站打开时间有两个因素,一个是网页加载速度,另一个是网站页面的大小.网站加载速度与用户所处的网络环境及主机性能有关,而网站页面的大小则由网站开发者决定,最主要的就是web前端开发工程师的工作.本文 ...

  4. linux 下select的1024限制

    1024限定的不只是监听的个数,还是文件描述符的最大值,注意,是值 今天编写模拟客户端程序进行测试,使用了select.之前一直错记成1024是对fd_set里fd个数的限制(我的程序是每次selec ...

  5. Constant-on-time buck-boost regulator converts a positive input to a negative output

    Buck regulators find wide application as step-down regulators for converting large positive input vo ...

  6. STN1110 Multiprotocol OBD to UART Interpreter

    http://www.obdsol.com/stn1110/ Safe, secure bootloader. Reflash the firmware in the field, even over ...

  7. 剑客vs刀客 Java vs .NET

    刀,无鞘的刀,重三十六斤六两三分,刀重而不大,重而不笨,千年寒铁精炼而成,刀身颀长,刀背轻薄,锋利异常,刀身桔黄色,隐隐泛着青色,刀面嵌龙凤图案,似龙吟,似凤鸣.刀柄带有两环,轻轻撞击会发出" ...

  8. PIR人体检查

    1.无变化时电压为0.8V左右 2.当检查到人体活动,电压保持为-1.3V,直到运动停止. 下面是示波器的截图

  9. [Android Studio] Android Studio中查看类的继承关系

    转载自:http://blog.csdn.net/hyr83960944/article/details/38098091 查看类的继承关系的快捷键F4,在Android Studio常用快捷键这篇文 ...

  10. [转]MySQL Explain

    Mysql Explain 详解 一.语法 explain < table_name > 例如: explain select * from t3 where id=3952602; 二. ...