xcode 在设计时方便地将视图控制器对象转换为表视图控制器(故事板)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16257793/
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
Conveniently convert a View Controller object to Table View Controller during design time (Storyboard)
提问by Matt
I know I can just delete the original View Controller and drop a Table View Controller in it's place inside the Storyboard, but this requires that I re-establish the relationships between the before and after view controllers.
我知道我可以删除原始的视图控制器并将表视图控制器放在故事板内的位置,但这需要我重新建立前后视图控制器之间的关系。
Is there an easier or more convenient way to convert the type of the object on the fly during design time? This seems like a very common task (at least in my own projects), and I would imagine that there is an option for that in Xcode.
在设计时是否有更简单或更方便的方法来即时转换对象的类型?这似乎是一项非常常见的任务(至少在我自己的项目中),我想在 Xcode 中有一个选项。
回答by davidisdk
As far as I know there is no UI in Xcode which lets you do this. You can however open the storyboard file in the xml editor (activating the version editor will do that) and change the name of the node from <viewController ...>
to <tableViewController ...>
. Don't forget to also change the closing tag to </tableViewController>
.
据我所知,Xcode 中没有可让您执行此操作的 UI。但是,您可以打开XML编辑器(激活文本编辑器将这样做)的故事板文件,并从改变节点的名称<viewController ...>
来<tableViewController ...>
。不要忘记还将结束标记更改为</tableViewController>
.
回答by mxch
What I did, is creating a UITableViewController in IB, open the Storyboard with a text editor, and copy all the nodes inside from the UIViewController to the UITableViewController.
我所做的是在 IB 中创建一个 UITableViewController,使用文本编辑器打开 Storyboard,然后将 UIViewController 中的所有节点复制到 UITableViewController。
I think that with this way there's less risk of deleting something important.
我认为通过这种方式删除重要内容的风险较小。
Before copying the sections objects, make sure that both tableviews (UIViewController and UITableViewController) have the same properties set like: static or dynamic cells, style (plain or grouped), etc.
在复制部分对象之前,请确保两个表视图(UIViewController 和 UITableViewController)具有相同的属性集,例如:静态或动态单元格、样式(普通或分组)等。
回答by Colin
The following doesn't exactly answer the question, but I think it may respond to the intent of the question.
以下内容并不能完全回答问题,但我认为它可能会回应问题的意图。
The easiest way to replace a regular view controller and view with a table view controller and table view is to drag a table view controller from the objects menu to a blank section of canvas, creating a new scene. If the table view scene should be the first view of your app, drag the arrow pointing to the view controller scene to the new scene. Now, if there's nothing you need from the old view controller, just delete it.
用表视图控制器和表视图替换常规视图控制器和视图的最简单方法是将表视图控制器从对象菜单拖到画布的空白部分,创建一个新场景。如果 table view 场景应该是您应用程序的第一个 view,请将指向视图控制器场景的箭头拖到新场景中。现在,如果您不需要旧视图控制器中的任何内容,只需将其删除即可。
See tutorial here.
请参阅此处的教程。
However, probably what you actually want if you want to be able to drill-down into detail views from the table view is a navigation controller. The navigation controller object creates a table view scene by default as its root view controller.
但是,如果您希望能够从表视图深入查看详细信息,那么您可能真正想要的是导航控制器。导航控制器对象默认创建一个表视图场景作为其根视图控制器。
回答by GoZoner
In Xcode, open the 'Utilities' pane (it appears from the right), click the 'Identity Inspector' and then in the 'Custom Class' region, select a different class. Note, however, this won't change the view in the linked-to controller. You'd need to remove the view and add a UITableView. Might then have to establish some delegate connections.
在 Xcode 中,打开“Utilities”窗格(从右侧出现),单击“Identity Inspector”,然后在“Custom Class”区域中,选择一个不同的类。但是请注意,这不会更改链接到控制器中的视图。您需要删除视图并添加 UITableView。然后可能必须建立一些委托连接。
I've done what you describe multiple times. Sometimes I delete the target and start again; sometimes I do as I describe and convert 'by-hand.'
我已经做了很多次你描述的事情。有时我删除目标并重新开始;有时我会按照我的描述进行操作并“手动”转换。