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

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

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.

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
  • Add a Storyboard to the Project
  • Set the Main Storyboard for the Project
  • Accessing the First View Controller
  • Configuring Table Views

Configure the Application Delegate

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-1Minimal application delegate header file


#import <UIKit/UIKit.h>


@interface AppDelegate : NSObject <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;


@end

Listing 1-2Minimal application delegate implementation file


#import "AppDelegate.h"


@implementation AppDelegate


@synthesize window = _window;


@end

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.

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

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]));


}


}

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

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

Add a Storyboard to the Project

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

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.

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:

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)

时间: 2024-11-08 23:45:19

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

Magic xpa 2.5发布 Magic xpa 2.5 Release Notes

Magic xpa 2.5 Release NotesNew Features, Feature Enhancements and Behavior ChangesCall with Destination – Backward Compatibility EnhancementsIn Online, the following scenarios are now possible:? Calling a program to a destination frame when the Call

深蓝词库转换2.7版发布——支持Mac原生输入法词库,QQ拼音新词库qcel格式

2020年过年期间,由于冠状病毒肺炎的流行,在家无事,就把搁置了很久的词库进行了改进.发布了2.7版:https://github.com/studyzy/imewlconverter/releases/tag/v2.7.0 转眼深蓝词库转换从诞生到现在都已经10个年头了,这是我做的最久的软件了.本次2.7版的更新主要包含了以下新特性: 一.MacOS原生简体拼音输入法自定义短语词库的支持 在MacOS的“系统偏好设置”中选择“键盘”,“文本”,即可看到,Mac简体拼音输入法的自定义短语词库.

深蓝词库转换2.4版发布,支持最新的搜狗用户词库备份bin格式

很高兴的告诉大家,感谢GitHub上的h4x3rotab提供python版的搜狗用户词库备份bin格式的解析算法,感谢tmxkn1提供了C#版的实现,深蓝词库转换终于迎来了一个重大更新,能够支持搜狗用户词库的bin格式备份的导出了.再也不用受到搜狗输入法的钳制,可以自由切换到其他输入法了.搜狗bin词库只解析到了用户词条和词频,没有拼音,所以如果要导出其他拼音输入法,中间转换工具会根据词条的内容重新生成拼音. 另外在2.4版中,增加了用户词频强制设置的功能,比如将搜狗用户词库bin格式备份转换为

基于Travis CI搭建Android自动打包发布工作流(支持Github Release及fir.im)

最近付费购买了Travis CI,Travis CI的收费模式很有意思,不是按项目或者用户,而是按工作进程收费,比如初级版本是$129/月,总共提供2个工作进程.在项目不多的情况下,除了用于跑单元测试外,不免想利用的更充分一些,因此抽空搭建了一套基于Travis CI的Android自动发布工作流. 未自动化前安卓开发总是避免不了这样的工作流程: 开发一些新功能,提交代码 完成一部分功能后,打包一个测试版APK 将测试版APK上传到QQ群 / 网盘 / Fir.im / 蒲公英等 在QQ群或发布

iOS UIKit 框架 346 篇文档分类整理 - 预告

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 当前正在进行的是 "iOS Foundation 框架 224 篇相关文档分类整理",量很大,但会根据实际开发中的使用频繁程序

Openstack liberty 创建实例快照源码分析1

Openstack liberty中也支持对云主机执行快照,快照是备份系统中一种常用的数据保护技术,在生产系统故障后,能通过快照将系统快速恢复到快照时间点:那Openstack中的云主机快照是否也支持这种故障恢复呢?请看下文: Openstack支持对处于运行或者停止状态的云主机执行快照,另外Openstack既可以从镜像启动云主机,也可以从启动磁盘启动云主机,根据条件组合,可以执行下面4中快照: 镜像启动云主机的离线快照 镜像启动云主机的在线快照 磁盘启动云主机的离线快照 磁盘启动云主机的在线

集成化的研发协作平台发展趋势

研发协作平台正在向高度集成化方向发展,在2008年6月份左右,作为企业研发协作平台的业界老大IBM,向全球软件客户强力推出了他们的下一代面向软件交付技术的研发协作平台Jazz,IBM 力图在不久的将来将IBM Rational的所有产品都逐步迁移到Jazz新平台下.高度集成化研发活动的各种点工具正成为集成化研发协作平台的一个新趋势.希望本文能够给读者了解集成化研发协作平台带来一些帮助. 在具体分析集成化的研发协作平台之前,我们先来了解一下绝大多数软件研发团队的一个典型工作情景: 软件开发人员通过

迅捷好用的在线PDF转Word转换工具

也许有人会问,PDF如何转换成Word?展现正在我们眼前的有这么多的PDF转换工具,那到底哪种PDF转 Word转换器会更好? 如何将PDF转成Word?迅捷PDF转换成Word在针对转换过程的处理上,通过深度PDF文件识别和处理技 术,将PDF文件的内容作为完整的数据进行解析,从而有效地确保了整个转换的过程更为完善,这也是为 什么迅捷PDF转换成Word转换器能够实现百分之百转换的主要原因. 作为知名的PDF文件格式,迅捷PDF转换成Word转换器具备如下特色功能: 高质量的PDF转换功能.众

Debug(调试) Release(发布) 区别

在开发环境的右上侧默认的构建配置模式是Debug(调试),为了方便程序的调试额外增加一些文件,但实际上程序开发完成发布的时候应该转为Release(发布)模式,刚开始我没有太注意这方面的细节,以至于开发出来随便一个小项目都是很大的文件大小,后来小研究了一番原因是出在这里,因为本人也是接触Delphi不久,都是靠网上和群里的零散资料结合自己的理解去整理去完善. 转换很方便,双击上图中的Release即可,或者鼠标右键Release选择Activate,这样发布出来的文件尺寸相对是较小的. 这样F9