简体   繁体   中英

Reuse static table view (iOS)

In my app I am using an UITableViewController for entering data. 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. So far so gut.

My problem: I cannot have static table (with sections and rows) in .xib file. 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? 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:] . It returns a new instance of the view controller, so it works just like loading a NIB.


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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