ios 想要创建一个很酷的静态 UI 但:“静态表视图仅有效......”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9277473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Want to create a cool static UI but : "Static table views are only valid..."
提问by Cehm
So I'm creating a View like :
所以我正在创建一个视图,如:
For this I'm trying to use a Storyboard in wich I add 2 TableViews (both as 'Static Cells') and then I manually add my Cell content directly from the storyboard...
为此,我尝试使用 Storyboard,其中我添加了 2 个 TableView(均作为“静态单元格”),然后我直接从情节提要中手动添加了我的单元格内容...
In my storyboard it looks great but when I build I get :
在我的故事板中它看起来很棒但是当我构建时我得到:
en.lproj/MainStoryboard.storyboard: error: Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances
en.lproj/MainStoryboard.storyboard:错误:非法配置:静态表视图仅在嵌入到 UITableViewController 实例中时才有效
If you guys have any ideas on this issue.
如果你们对这个问题有任何想法。
Thanks !
谢谢 !
采纳答案by ?ystein
Add a UITableViewController to your view. It should hold a UITableView. Define this as a static table view, and make it grouped. Add two sections. One with one row, and the other with two rows. Add your Labels buttons and sliders to the rows again.
将 UITableViewController 添加到您的视图中。它应该包含一个 UITableView。将其定义为静态表视图,并将其分组。添加两个部分。一排一排,另一排两排。再次将标签按钮和滑块添加到行中。
I do not know why you would want to have two UITableViews here?
我不知道你为什么要在这里有两个 UITableViews?
回答by juanignaciosl
I've also ran into an issue when changing an existing custom view controller, making it extends UITableViewController. XCode isn't smart enough and won't realize it already fits its requirements.
在更改现有的自定义视图控制器时,我也遇到了一个问题,使其扩展了 UITableViewController。XCode 不够智能,不会意识到它已经符合其要求。
You can solve this problem by editing storyboard source code and changing <viewController ...
to <tableViewController...
.
您可以通过编辑故事板源代码并更改<viewController ...
为<tableViewController...
.
Original source: https://plus.google.com/108665969482300807329/posts/J4mCASMA3pZ
原文出处:https: //plus.google.com/108665969482300807329/posts/J4mCASMA3pZ
回答by Radu Simionescu
The only way to make this work in Xcode 6, and the way Apple intended this to work is to embed a TableViewController in a container view, if you must. It seems that you cannot hack your way through as described by juanignaciosl, in Xcode 6.
在 Xcode 6 中实现此功能的唯一方法,以及 Apple 打算使用的方式是将 TableViewController 嵌入到容器视图中,如果必须的话。在 Xcode 6 中,您似乎无法按照 juanignaciosl 的描述进行破解。
So the steps would be as follows:
所以步骤如下:
- Create a table view controller
- replace the table view in this controller with the table from your "problematic" view controller, with all its static cells and so on
- 创建一个表视图控制器
- 用您的“有问题”视图控制器中的表格替换此控制器中的表格视图,及其所有静态单元格等等
If your table view is part of a more complex ui and it is not the main view of your view controller then continue as below
如果您的表视图是更复杂的 ui 的一部分,并且它不是您的视图控制器的主视图,则继续如下
- create a containerView in your "problematic" view controller, in the same position as your now-moved static table view. This will also create automatically another viewcontroller and a seque - delete those.
- left click drag or ctrl drag from the container view to the tableviewcontroller which contains your static table and choose embed
- 在“有问题”的视图控制器中创建一个 containerView,与您现在移动的静态表视图的位置相同。这还将自动创建另一个视图控制器和一个序列 - 删除它们。
- 左键单击或 ctrl 从容器视图拖动到包含静态表的 tableviewcontroller 并选择嵌入
This is not as nice as before, because your tableview is stripped away in a separate view controller in interface builder and this might have an impact on your existing code and outlets. But for big static tables it is the better alternative to generating all the content dynamically.
这不像以前那么好,因为您的 tableview 在界面构建器中的单独视图控制器中被剥离,这可能会对您现有的代码和插座产生影响。但是对于大型静态表,它是动态生成所有内容的更好选择。
回答by Ash Var
You can make it dynamic and then switch of scrolling:
您可以将其设为动态,然后切换滚动:
[yourTableName setScrollEnabled:NO];