且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不使用Storyboard的情况下在UITableView中使用静态单元格?

更新时间:2023-09-24 21:29:28

静态表格视图单元格仅在使用故事板时可用。但是,如果您没有为整个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.