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

查看:26
本文介绍了如何在不使用 Storyboards 的情况下在 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 拖到屏幕上时,属性检查器中没有内容 > 静态"菜单.

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

我已经尝试让我的控制器子类 UITableViewController,但这没有帮助——我仍然没有选择在属性检查器中使用静态单元格.

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 上环顾四周,但没有找到这个问题的任何现有答案.所有现有问题都与故事板(我没有使用)有关,而不是与 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 的任何建议?

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.

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

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