ios 带有静态单元格的 UITableView 不会出现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8639780/
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
UITableView with static cells does not appear
提问by adum
I have created a new Xcode project using Storyboards (tab view template). I added a couple of view controllers to my storyboard, and wanted to use a UITableView with static cells for one. I created it, but when I run in the simulator the cells don't appear. I haven't changed anything in the project except for this storyboard file. I am showing screenshots of the storyboard editor and the simulator running. The label shows up, so the view is loading correctly. I set the background color to gray so I can see the talbeview is loading. All cells are set to visible. I changed their style to Basic and edited the label, and added a disclosure indicator, that's all.
我使用 Storyboards(选项卡视图模板)创建了一个新的 Xcode 项目。我在我的故事板中添加了几个视图控制器,并希望使用带有静态单元格的 UITableView 作为其中一个。我创建了它,但是当我在模拟器中运行时,单元格没有出现。除了这个故事板文件之外,我没有更改项目中的任何内容。我正在展示故事板编辑器和模拟器运行的屏幕截图。标签显示出来,所以视图加载正确。我将背景颜色设置为灰色,以便我可以看到 talbeview 正在加载。所有单元格都设置为可见。我将它们的样式更改为 Basic 并编辑了标签,并添加了一个披露指示符,仅此而已。
采纳答案by Dennis Mathews
Do you want to try using the TableViewController rather than the Generic View controller ?
您想尝试使用 TableViewController 而不是通用视图控制器吗?
回答by Joe Y
Don't implement any of the methods below when you use the static table view:
使用静态表视图时不要实现以下任何方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
回答by EeKay
As stated on Ray Wenderlich's website (in this post: Beginning Storyboards in iOS 5 Part 2, section "The Add Player Screen at Work" ):
正如 Ray Wenderlich 的网站上所述(在这篇文章中:iOS 5 第 2部分中的开始故事板,“工作中的添加播放器屏幕”部分):
One more thing about static cells, they only work in UITableViewController. The Storyboard Editor will let you add them to a Table View object inside a regular UIViewController, but this won't work during runtime. The reason for this is that UITableViewController provides some extra magic to take care of the data source for the static cells. Xcode even prevents you from compiling such a project with the error message: “Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances”.
关于静态单元格的另一件事,它们只能在 UITableViewController 中工作。Storyboard Editor 将允许您将它们添加到常规 UIViewController 内的 Table View 对象,但这在运行时不起作用。这样做的原因是 UITableViewController 提供了一些额外的魔法来处理静态单元格的数据源。Xcode 甚至阻止你编译这样一个带有错误消息的项目:“非法配置:静态表视图仅在嵌入 UITableViewController 实例时才有效”。
Had the same issue but this makes things clear...
有同样的问题,但这使事情变得清楚......
回答by zqy
You can add a Container View and embed a UITableViewController in that container. Then you can manage your static cells inside the new controller.
您可以添加一个容器视图并在该容器中嵌入一个 UITableViewController。然后您可以在新控制器内管理您的静态单元。
回答by dave
I was experiencing the same problem, and the fix that worked for me was to present the static UITableViewController subclass using performSegue.
Presenting the old waywith [[self navigationController] present...]
did not result in the static table view properly loading its cells.
我遇到了同样的问题,对我有用的修复方法是使用旧方式performSegue.
呈现静态 UITableViewController 子类,并没有导致静态表视图正确加载其单元格。[[self navigationController] present...]