redribben

MenuViewController

Nov 11th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  MenuViewController.m
  3. //  Радио СВЕТ
  4. //
  5. //  Created by Bogdan Michalchuk on 11/10/14.
  6. //  Copyright (c) 2014 Радио CBET. All rights reserved.
  7. //
  8.  
  9. #import "MenuViewController.h"
  10. #import "ECSlidingViewController.h"
  11. #import "UIViewController+ECSlidingViewController.h"
  12.  
  13. @interface MenuViewController ()
  14.  
  15. @property (strong, nonatomic) NSArray *menu;
  16.  
  17. @end
  18.  
  19. @implementation MenuViewController
  20.  
  21. @synthesize menu;
  22.  
  23. - (void)viewDidLoad {
  24.     [super viewDidLoad];
  25.    
  26.     // Uncomment the following line to preserve selection between presentations.
  27.     // self.clearsSelectionOnViewWillAppear = NO;
  28.    
  29.     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  30.     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  31.    
  32.     self.menu = [NSArray arrayWithObjects:@"Main", @"Second", nil];
  33.    
  34.     [self.slidingViewController setAnchorRightRevealAmount:200.0f];
  35.     self.slidingViewController.underLeftWidthLayout = ECFullWidth;
  36.    
  37. }
  38.  
  39. - (void)didReceiveMemoryWarning {
  40.     [super didReceiveMemoryWarning];
  41.     // Dispose of any resources that can be recreated.
  42. }
  43.  
  44. #pragma mark - Table view data source
  45.  
  46. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  47.     // Return the number of sections.
  48.     return 1;
  49. }
  50.  
  51. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  52.     // Return the number of rows in the section.
  53.     return [self.menu count];
  54. }
  55.  
  56.  
  57. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  58.     NSString *cellIdentifier = @"Cell";
  59.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  60.     if (cell == nil) {
  61.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
  62.     }
  63.    
  64.     cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.menu objectAtIndex:indexPath.row]];
  65.    
  66.     return cell;
  67. }
  68.  
  69.  
  70. /*
  71. // Override to support conditional editing of the table view.
  72. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  73.     // Return NO if you do not want the specified item to be editable.
  74.     return YES;
  75. }
  76. */
  77.  
  78. /*
  79. // Override to support editing the table view.
  80. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  81.     if (editingStyle == UITableViewCellEditingStyleDelete) {
  82.         // Delete the row from the data source
  83.         [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  84.     } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  85.         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  86.     }  
  87. }
  88. */
  89.  
  90. /*
  91. // Override to support rearranging the table view.
  92. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  93. }
  94. */
  95.  
  96. /*
  97. // Override to support conditional rearranging of the table view.
  98. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
  99.     // Return NO if you do not want the item to be re-orderable.
  100.     return YES;
  101. }
  102. */
  103.  
  104. /*
  105. #pragma mark - Navigation
  106.  
  107. // In a storyboard-based application, you will often want to do a little preparation before navigation
  108. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  109.     // Get the new view controller using [segue destinationViewController].
  110.     // Pass the selected object to the new view controller.
  111. }
  112. */
  113.  
  114. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  115.     NSString *identifier = [NSString stringWithFormat:@"%@", [self.menu objectAtIndex:indexPath.row]];
  116.    
  117.     UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
  118.    
  119.     [self.slidingViewController anchorTopViewOffScreen:ECRight animation:nil onComplete:^{
  120.         CGRect frame = self.slidingViewController.topViewController.view.frame;
  121.         self.slidingViewController.topViewController = newTopViewController;
  122.         self.slidingViewController.topViewController.view.frame = frame;
  123.         [self.slidingViewController resetTopView];
  124.     }];
  125. }
  126.  
  127. @end
Advertisement
Add Comment
Please, Sign In to add comment