Skip to content

Instantly share code, notes, and snippets.

@jcavar
Created May 14, 2014 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcavar/c6f097cbf33af0216eb3 to your computer and use it in GitHub Desktop.
Save jcavar/c6f097cbf33af0216eb3 to your computer and use it in GitHub Desktop.
Preffered way to implement side controller when using ViewDeck(https://github.com/Inferis/ViewDeck)
@interface SideViewController ()
@property (strong, nonatomic) IBOutlet UITableView *tableViewSide;
@property (strong, nonatomic) NSArray *options;
@end
@implementation SideViewController
#pragma mark - Object lifecycle
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_options = @[@"Points of Interest", @"Events", @"News", @"Jobs", @"Contact"];
_navigationViewControllers = [NSMutableArray array];
NSArray *controllers = @[HomeViewController.class, EventsViewController.class, NewsViewController.class, JobsViewController.class, ContactsViewController.class];
for (Class class in controllers) {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[class alloc] initWithNibName:NSStringFromClass(class) bundle:nil]];
navigationController.navigationBar.translucent = NO;
navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.24 green:0.62 blue:0.42 alpha:1];
navigationController.navigationBar.tintColor = [UIColor whiteColor];
[_navigationViewControllers addObject:navigationController];
}
}
return self;
}
#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UITableViewDataSource methods
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"SideCell";
SideCell *cell = (SideCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"SideCell" owner:self options:nil] lastObject];
}
cell.labelTitle.text = self.options[indexPath.row];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.options.count;
}
#pragma mark - UITableViewDelegate methods
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.deckController.centerController = self.navigationViewControllers[indexPath.row];
[appDelegate.deckController toggleLeftViewAnimated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment