如何在不使用Storyboard的情况下在UITableView中使用静态单元格? [英] How to use static cells in UITableView without using Storyboards?

查看:114
本文介绍了如何在不使用Storyboard的情况下在UITableView中使用静态单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个现有的ViewController + xib,现在我想添加一个带有静态单元格的UITableView,如下所示:

I have an existing ViewController + xib in my project, and now I want to add a UITableView with static cells, like this:

但是当我将UITableView拖到我的屏幕上时在Attributes Inspector中没有Content> Static菜单。

But when I drag a UITableView onto my screen I don't have the "Content > Static" menu in the Attributes Inspector.

我试过让我的控制器子类UITableViewController,但这没有帮助 - 我仍然不要在Attributes Inspector中选择使用静态单元格。

I've tried making my controller subclass UITableViewController, but that doesn't help -- I still don't get the option to use static cells in Attributes Inspector.

我在StackOverflow上看了一下,但是没有找到这个问题的任何现有答案。所有现有的问题都与Storyboard(我没有使用)有关,而不是xib文件。

I've looked around on StackOverflow but haven't found any existing answers to this question. All the existing questions relate to Storyboards (which I'm not using) instead of xib files.

我的猜测是,当你添加一个UITableViewController时,Xcode会有一些魔力到故事板,但不是当您将现有的xib更改为从UITableViewController继承时。

My guess is that Xcode does some kind of magic when you add a UITableViewController to a storyboard, but not when you change an existing xib to inherit from UITableViewController.

有关如何将静态单元格的表视图添加到现有xib的任何建议吗? / p>

Any advice how how to add a table view with static cells to an existing xib?

推荐答案

静态表格视图单元格仅在使用故事板时可用。但是,如果您没有为整个UI使用故事板,您仍然可以将它们用于单个屏幕而不是屏幕集合。

Static table view cells are only available when using storyboards. However, if you aren't using storyboards for your entire UI you can still use them for individual screens instead of a collection of screens.

为此,您可以创建一个UIStoryboard文件上有一个视图控制器,它的文件所有者设置为自定义视图控制器子类。将VC的标识符设置为某个值。当您想要显示它时,获取故事板,然后通过从故事板创建VC来实例化您的视图控制器子类。

To do this you can create a UIStoryboard file with a single view controller on it that has it's File's Owner set to your custom view controller subclass. Set the VC's identifier to some value. When you want to display this, get the storyboard and then instantiate your view controller subclass by creating the VC from your storyboard.

UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"your storyboard" bundle:nil];
CustomViewController = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"custom identifier"];

您可以像往常一样在您的应用中展示此VC。

You can present this VC as usual in your app.

这是开始使用故事板而不必转换整个应用程序以使用它们的好方法。

This is a great way to start using storyboards without having to convert your entire app to use them.

这篇关于如何在不使用Storyboard的情况下在UITableView中使用静态单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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