Skip to content

Instantly share code, notes, and snippets.

@sneakyness
Forked from anonymous/gist:3346690
Created August 14, 2012 05:49
Show Gist options
  • Select an option

  • Save sneakyness/3346693 to your computer and use it in GitHub Desktop.

Select an option

Save sneakyness/3346693 to your computer and use it in GitHub Desktop.

Revisions

  1. sneakyness renamed this gist Aug 14, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. sneakyness revised this gist Aug 14, 2012. 1 changed file with 7 additions and 12 deletions.
    19 changes: 7 additions & 12 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -81,26 +81,21 @@

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    STableViewController *controller = [_navigationArray objectAtIndex:indexPath.row];

    [self updateOnlyCurrentTableViewToScrollToTop:controller];
    UITableViewController *controller = [_navigationArray objectAtIndex:indexPath.row];

    NSArray *controllers = [NSArray arrayWithObject:controller];
    [self updateOnlyCurrentTableViewToScrollToTop:controller];
    [MFSideMenuManager sharedManager].navigationController.viewControllers = controllers;
    [MFSideMenuManager sharedManager].navigationController.menuState = MFSideMenuStateHidden;
    }


    - (void)updateOnlyCurrentTableViewToScrollToTop:(STableViewController *)current {
    BOOL answer;
    for (STableViewController *c in _navigationArray) {
    answer = current == c;
    NSLog(answer ? @"Yes" : @"No");
    - (void)updateOnlyCurrentTableViewToScrollToTop:(UITableViewController *)current {
    [self.tableView setScrollsToTop:NO];
    for (UITableViewController *c in _navigationArray) {
    if ([c isViewLoaded]) {
    c.tableView.scrollsToTop = answer;
    c.tableView.scrollEnabled = answer;
    c.tableView.scrollsToTop = (current==c);
    }
    }
    }

    @end
    @end
  3. @invalid-email-address Anonymous created this gist Aug 14, 2012.
    106 changes: 106 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,106 @@
    //
    // SideMenuViewController.m
    // MFSideMenuDemo
    //
    // Created by Michael Frederick on 3/19/12.

    #import "ANSideMenuController.h"
    #import "MFSideMenu.h"
    #import "ANGlobalStreamController.h"
    #import "ANUserStreamController.h"
    #import "ANUserMentionsController.h"
    #import "ANUserViewController.h"

    #import "STableViewController.h"

    @interface ANSideMenuController ()

    - (void)updateOnlyCurrentTableViewToScrollToTop:(STableViewController *)current;

    @end

    @implementation ANSideMenuController
    {
    ANUserStreamController *userStream;
    ANUserMentionsController *mentionsStream;
    ANGlobalStreamController *globalStream;
    ANUserViewController *userInfo;
    }

    - (id)init
    {
    self = [super init];

    userStream = [[ANUserStreamController alloc] init];
    mentionsStream = [[ANUserMentionsController alloc] init];
    globalStream = [[ANGlobalStreamController alloc] init];
    userInfo = [[ANUserViewController alloc] init];

    _navigationArray = @[userStream, mentionsStream, globalStream, userInfo];

    return self;
    }

    - (void)viewDidLoad
    {
    [super viewDidLoad];

    [self.tableView setScrollEnabled:NO];
    }

    #pragma mark - UITableViewDataSource

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return 4;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    ANBaseStreamController *controller = [_navigationArray objectAtIndex:indexPath.row];
    cell.textLabel.text = controller.sideMenuTitle;

    return cell;
    }


    #pragma mark - UITableViewDelegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    STableViewController *controller = [_navigationArray objectAtIndex:indexPath.row];

    [self updateOnlyCurrentTableViewToScrollToTop:controller];

    NSArray *controllers = [NSArray arrayWithObject:controller];
    [MFSideMenuManager sharedManager].navigationController.viewControllers = controllers;
    [MFSideMenuManager sharedManager].navigationController.menuState = MFSideMenuStateHidden;
    }


    - (void)updateOnlyCurrentTableViewToScrollToTop:(STableViewController *)current {
    BOOL answer;
    for (STableViewController *c in _navigationArray) {
    answer = current == c;
    NSLog(answer ? @"Yes" : @"No");
    if ([c isViewLoaded]) {
    c.tableView.scrollsToTop = answer;
    c.tableView.scrollEnabled = answer;
    }
    }
    }

    @end