Created
August 14, 2012 05:47
-
-
Save anonymous/3346690 to your computer and use it in GitHub Desktop.
Scroll to Top
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment