简体   繁体   English

从Interface Builder中的TabBarController使用initWithStyle初始化TableViewController?

[英]initialize TableViewController with initWithStyle from TabBarController in Interface Builder?

I have a TabBarController in Interface Builder. 我在Interface Builder中有一个TabBarController。 I assigned a subclassed UITableViewController as ViewController of Tab 2, works fine. 我将一个子类化的UITableViewController分配为Tab 2的ViewController,工作正常。

But I would like to set the style of the UITableViewController's TableView to UITableViewStyleGrouped. 但是我想将UITableViewController的TableView的样式设置为UITableViewStyleGrouped。 The only way to do this is apparently(?) to call UITableViewController:initWithStyle: 唯一的方法显然是(?)调用UITableViewController:initWithStyle:

So my question is: How can I a) either tell interface builder to initialize the viewcontroller with initWithStyle or b) use some other way to achieve this? 所以我的问题是:如何a)告诉界面生成器使用initWithStyle初始化viewcontroller或b)使用其他方式来实现此目的? I tried already to override initWithStyle in the ViewController, but apparently it is not called when the tabbarcontroller shows the viewcontroller (it is however called when initializing the viewcontroller programmatically). 我已经尝试覆盖ViewController中的initWithStyle,但是显然在tabbarcontroller显示viewcontroller时不会调用它(但是在以编程方式初始化viewcontroller时会调用它)。

I like the way I can control the tab bar controller and its viewcontrollers from IB and wouldn't want to call the viewcontroller programmatically unless there is no other way. 我喜欢从IB控制选项卡栏控制器及其视图控制器的方式,除非没有其他方法,否则我不想以编程方式调用视图控制器。

As always, thanks for any reply! 与往常一样,感谢您的答复!

I think I found a solution: Adding a nib file to the view controller: 我想我找到了一个解决方案:将nib文件添加到视图控制器:

  • Make sure the viewcontroller within the tabbarcontroller is of (sub-)class TableViewController 确保tabbarcontroller中的viewcontroller是TableViewController的(子)类
  • Drag a TableView from the Library below the TableViewController 从TableViewController下面的库中拖动TableView
  • IB sets delegate and datasource, and the style is changeable in the TableView IB设置委托和数据源,并且样式可以在TableView中更改

Good luck to anyone else having this problem! 祝其他人遇到这个问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM