在带有 Xcode 4.2 的故事板 UIView 中使用静态单元格 [英] Using static cells in a storyboard UIView with Xcode 4.2

查看:31
本文介绍了在带有 Xcode 4.2 的故事板 UIView 中使用静态单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Xcode 4.2 中的 Storyboard 设计器创建一个非常基本的登录屏幕.我想要一个包含登录名和密码字段的分组表视图.视图上还有一些其他元素,例如登录按钮、忘记密码链接等.此外,当输入字段具有焦点时,应该能够点击背景以关闭键盘.

在 Xcode 4.2 之前,我使用实现了 UITableViewDataSource 协议、生成和返回单元格等的 UIView 完成了这项工作.

在 Xcode 4.2 中,这一切都感觉非常接近能够通过静态单元格选项在视觉上完成,但不允许使用静态单元格,除非表格是 UITableViewController(或子类)的一部分.我没有看到使用 TableViewController 在这个场景中布局我需要的元素的方法,所以我想知道这里是否有更好的方法.

这是我要的模拟布局:

有没有办法让故事板设计师完成这个用例?

解决方案

1) 如果你的视图控制器不是 UITableViewController 的实例,这是不可能的.

根据 Apple 的文档(https://developer.apple.com/library/ios/#releasenotes/Miscellaneous/RN-AdoptingStoryboards/_index.html#//apple_ref/doc/uid/TP40011297):><块引用>

对于作为 UITableViewController 实例视图的表视图,您可以直接在故事板中配置静态内容.

2) 但是 UITableViewController 有很多限制,使您无法在许多情况下使用它:

http://www.skylarcantu.com/blog/2009/09/24/dont-use-uitableviewcontroller-really/

结论:它本质上使故事板中的静态单元格在大多数情况下不可行.

I am attempting to create a very basic login screen, using the Storyboard designer in Xcode 4.2. I'd like a grouped table view to contain the login and password fields. There are some other elements on the view, such as a login button, a forgot password link, etc. Additionally, the background should be able to be tapped to dismiss the keyboard, when a input field has focus.

Pre-Xcode 4.2, I accomplished this with a UIView that implemented the UITableViewDataSource protocol, generated and returned cells, etc.

In Xcode 4.2, this all feels very close to be able to be done visually, with the static cell option, but you are not allowed to use static cells unless the table is part of a UITableViewController (or subclass). I don't see a way to layout the elements that I need in this scene with a TableViewController, so I'm wondering if there's a better approach here.

Here's the mocked up layout I'm going for:

Is there a way to accomplish this use case with the storyboard designer?

解决方案

1) If your view controller is not an instance of UITableViewController, this is not possible.

According to Apple's documentation (https://developer.apple.com/library/ios/#releasenotes/Miscellaneous/RN-AdoptingStoryboards/_index.html#//apple_ref/doc/uid/TP40011297):

For a table view that is the view of a UITableViewController instance, you can configure static content directly in the storyboard.

2) But UITableViewController has many limitations which prevents you to use it in many scenarios:

http://www.skylarcantu.com/blog/2009/09/24/dont-use-uitableviewcontroller-really/

Conclusion: it essentially makes the static cells in storyboard not feasible in most cases.

这篇关于在带有 Xcode 4.2 的故事板 UIView 中使用静态单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆