如何在嵌入UIViewController的UITableView中直观地创建和使用静态单元格 [英] How to visually create and use static cells in a UITableView embedded in a UIViewController

查看:189
本文介绍了如何在嵌入UIViewController的UITableView中直观地创建和使用静态单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode 4.2,并使用Storyboard构建了我的UI。我需要创建一个包含UITableView上方和下方内容的视图,我可以通过使用UIViewController来实现这一点。 UITableViewController不允许您在表格上方或下方添加内容。您可以使用表格页眉/页脚,但这不适用于我想要实现的目标。

I'm using XCode 4.2 and have built my UI using Storyboards. I need to create a view that has content above and below a UITableView and I can achieve this by using a UIViewController. A UITableViewController does not let you add content above or below the table. You can use the table header/footer but that doesn't work for what I would like to achieve.

我现在有一个嵌入了UITableView的UIViewController。我可以相应地调整UITableView的高度和宽度,这为我提供了我正在寻找的UI布局。

I now have a UIViewController with a UITableView embedded in it. I can adjust the height and width of the UITableView accordingly which provides me the UI layout that I am looking for.

我可以自定义UITableView中的静态单元格但是当我尝试构建我得到以下错误:

I can customize the static cells in the UITableView but when I try to build I get the following error:


非法配置:静态表视图仅在嵌入UITableViewController实例时有效

Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances

我的问题是其他人如何解决这个问题?使用静态单元格创建一个tableview并在视觉上进行布局是非常好的,但显然由于某些我无法理解的原因而不允许这样做。由于我的视觉布局要求,我无法切换到UITableViewController。

My question is how are others getting around this? Creating a tableview with static cells and laying them out visually is very nice but apparently that is not allowed for some reason that I cannot understand. I can't switch to a UITableViewController because of my visual layout requirements.

非常感谢任何帮助。

推荐答案

你是对的。在storyboard中,你不能在viewController中嵌入带有静态单元格的tableView。解决它的一种方法(我自己没有尝试过,所以我不确定它是否有效)可以是你在静态单元格的故事板中创建UITableViewController的实例。将一个UIView实例添加到viewController,然后以编程方式将UITableViewController的tableView加载到viewController的UIView中。

You are right. In storyboard, you cannot have a tableView with static cells embedded in a viewController. One way around it (I have not tried it myself, though, so I am not sure if it works) can be that you create an instance of UITableViewController in storyboard with static cells. Add an instance of UIView to your viewController, and then programmatically load the tableView of the UITableViewController into the UIView of your viewController.

这篇关于如何在嵌入UIViewController的UITableView中直观地创建和使用静态单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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