Does anyone have an idea about how to use a single UITableView
in multiple ViewControllers
?
I need to create a common UITableView
for all my view controllers and use it through out the application.
Any help is appreciated.
Does anyone have an idea about how to use a single UITableView
in multiple ViewControllers
?
I need to create a common UITableView
for all my view controllers and use it through out the application.
Any help is appreciated.
Use ContainerView, you can drag ContainerView into your ViewControllers in a storyboard, adjust the size according what you need. You use the ContainerView in all that ViewController that need the TableView.
Attached is a screen shot of one of my app that is using ContainerView that contains a TableView inside the ViewController. I am using the same thing in 2 different ViewControllers.
You can use singleton. Here is an example:
CommonTableView.h file:
#import <Foundation/Foundation.h>
@interface CommonTableView : UITableView <UITableViewDelegate>
+ (CommonTableView *)sharedInstance;
@end
CommonTableView.m file:
#import “CommonTableView.h”
CommonTableView *sharedInstance = nil;
@implementation CommonTableView
+ (CommonTableView *)sharedInstance
{
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [[super allocWithZone:nil] init];
});
return sharedInstance;
}
- (id)init
{
self = [super init];
if (self) {
self.delegate = self;
//customize your table view
}
return self;
}
#pargma mark - UITableView delegate
//…
@end
Then you can access your tableView with [CommonTableView sharedInstance] in the UIViewControllers that you want.