简体   繁体   English

重用静态表格检视(iOS)

[英]Reuse static table view (iOS)

In my app I am using an UITableViewController for entering data. 在我的应用程序中,我使用UITableViewController输入数据。 Now I want to use the same table in another view controller for modifying the data. 现在,我想在另一个视图控制器中使用相同的表来修改数据。

My idea: Implement an additional view controller and let these two inherit from it. 我的想法:实现一个额外的视图控制器,并让这两个继承自它。 All controls are the same and most of the behavior as well. 所有控件都是相同的,并且大多数行为也是如此。 However, in both I need some additional properties, in the one a delegate, and 1-2 methods must be overridden. 但是,在这两种方法中,我都需要一些其他属性,在其中一个是委托,并且必须重写1-2个方法。 So far so gut. 到目前为止到目前为止。

My problem: I cannot have static table (with sections and rows) in .xib file. 我的问题:.xib文件中不能有静态表(带有节和行)。 So I cannot really reuse my table. 因此,我无法真正重用我的表。

My question: How do I use such inherited controllers in storyboards? 我的问题:如何在情节提要中使用此类继承的控制器? I need one for the common superclass. 我需要一个普通的超类。 However, I cannot use it directly, it doesn't have all properties and methods that I need. 但是,我不能直接使用它,它没有我需要的所有属性和方法。 And I really don't want to try doing everything in one class. 而且我真的不想尝试在一堂课中做所有事情。 So what can I do? 那我该怎么办?

Have you already checked out the free Sensible TableView framework? 您是否已经签出了免费的Sensible TableView框架? Seems to provide what you need out of box. 似乎可以开箱即用地提供您所需的东西。

you can just make the table view controller in the storyboard, and use 您只需在情节提要中创建表格视图控制器,然后使用

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 
ExampleView *eg = [storyboard instantiateViewControllerWithIdentifier:@"ExampleView"];

and keep it as a singleton and just segue to it when you need it. 并将其保持为单例,并在需要时将其隔离。 then you will be able to use it multiple times without it being destroyed 那么您将可以多次使用它而不会被破坏

In a storyboard, you can always load a view using -[UIStoryboard instantiateViewControllerWithIdentifier:] . 在情节-[UIStoryboard instantiateViewControllerWithIdentifier:] ,您始终可以使用-[UIStoryboard instantiateViewControllerWithIdentifier:]加载视图。 It returns a new instance of the view controller, so it works just like loading a NIB. 它返回视图控制器的新实例,因此其工作方式与加载NIB相同。


id vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Static Table"];
[self.navigationController pushViewController:vc animated:YES];

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

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