Antiohia
Antiohia

Reputation: 1232

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?

Upvotes: 0

Views: 195

Answers (3)

Matt
Matt

Reputation: 2411

Have you already checked out the free Sensible TableView framework? Seems to provide what you need out of box.

Upvotes: 1

Jeffery Thomas
Jeffery Thomas

Reputation: 42598

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];

Upvotes: 0

Fonix
Fonix

Reputation: 11597

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

Upvotes: 0

Related Questions