简体   繁体   English

如何使用Storyboard在另一个Controller中子视图UITableViewController

[英]How to subview a UITableViewController within another Controller using Storyboards

I have encapsulated all my table view logic on a UITableViewController that is linked to a view. 我已将所有表视图逻辑封装在链接到视图的UITableViewController上。 This was done using storyboards. 这是使用故事板完成的。

I would like to embed this logic and view within another view controller / view (kind of like a header information with a scrollable table beneath.) 我想在另一个视图控制器/视图中嵌入这个逻辑和视图(有点像下面带有可滚动表的标题信息。)

I have the following components: CustomViewController which is linked to a UIView (dragged in from storyboard) CustomTableViewController which is linked to a UITableView (dragged in from storyboard) 我有以下组件:CustomViewController链接到UIView(从故事板中拖入)CustomTableViewController链接到UITableView(从故事板中拖入)

Essentially I am trying to mimic the scenario of the Stopwatch in the iOS clock app 基本上我试图模仿iOS时钟应用程序中秒表的场景

  • What is the beast approach to this? 这种野兽方法是什么?
  • How is it done programatically? 它是如何以编程方式完成的?
  • Can this be done on the storyboard somehow? 这可以在故事板上以某种方式完成吗?

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks 谢谢

Ok figured it out. 好想通了。 This solution is iOS 5 specific since this feature was added there. 此解决方案是iOS 5特定的,因为此处添加了此功能。 This method works with storyboards. 此方法适用于故事板。

Setup: The intention is to host one view controllers view and logic within another controller. 设置:目的是在另一个控制器中托管一个视图控制器视图和逻辑。

  1. Since there is no intrinsic way to reference the child view controller in the storyboard, we need to give the view controller a name. 由于没有内在的方法来引用故事板中的子视图控制器,我们需要为视图控制器命名。 This can be done by filling out the "Identifier" attribute on the controller in the storyboard. 这可以通过填充故事板中控制器上的“标识符”属性来完成。 NOTE: Make sure you are giving the controller the identifier and not the controllers view. 注意:确保为控制器提供标识符而不是控制器视图。

  2. Instantiate the controller you want to aggregate. 实例化要聚合的控制器。 This can be done from the hosting controller. 这可以从托管控制器完成。

     UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ControllerIdentifier"]; 
  3. Add the child controller to the parent controller 将子控制器添加到父控制器

     [self addChildViewController: controller]; 
  4. Add the child controllers view to the parent controllers view. 将子控制器视图添加到父控制器视图。 Note if you have a place holder view in the parent controller you wish to add the child view to, then this is where you do it. 请注意,如果您希望将子视图添加到父控制器中的占位符视图,则可以在此处执行此操作。 Here I add it the a UIView called stage in the parent controller. 在这里,我在父控制器中添加一个名为stage的UIView。

     [self clearStage]; [self.stageView addSubview:controller.view]; presentedController.view.frame = self.stageView.bounds; 

And that is it. 就是这样。 Pretty simple. 很简单。 I have used it successfully with switching controllers and view in a home made tab control. 我已成功使用它与切换控制器和在自制选项卡控件中查看。 The sub controller enlists its views in the view lifecycle, so the viewDidLoad , etc all work as expected in this child view controller. 子控制器在视图生命周期中查看其视图,因此viewDidLoad等都在此子视图控制器中按预期工作。

Hopes this helps someone. 希望这有助于某人。

暂无
暂无

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

相关问题 使用故事板设置UITableViewController的委托 - Setting delegate of a UITableViewController using Storyboards 如何从情节提要中的子视图(另一个视图控制器)内的按钮推动新的视图控制器 - How can I push a new View Controller from a button within a subView (another View Controller) in Storyboard 使用故事板在UITableViewController上显示UIScrollVIew - Show UIScrollVIew on top of UITableViewController using storyboards 如何在Storyboards中将工具栏添加到UITableViewController的底部? - How to add a toolbar to the bottom of a UITableViewController in Storyboards? 使用情节提要板时如何使用Typhoon导航到导航控制器中的控制器 - How to navigate to a controller in a navigation controller using Typhoon when using storyboards 有谁知道如何在不使用StoryBoards的情况下使用UITableViewController在Xamarin.iOs中实现UISearchController? - Does anyone know how to use UITableViewController to implement UISearchController in Xamarin.iOs without using StoryBoards? 如何使用故事板与标签栏控制器作为初始控制器共享UIManagedDocument? - How to share a UIManagedDocument using Storyboards with a Tab Bar Controller as initial controller? 如何使用PFQueryViewController作为UITableViewController的子视图? - How can I use PFQueryViewController as a subview of UITableViewController? 如何在UITableViewController中引用自定义UIView的子视图按钮 - How to Refer to a Subview Button of Custom UIView in UITableViewController UITableViewController,情节提要和UIKeyboard - UITableViewController, Storyboards and UIKeyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM