Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "LeftSideMenuViewController.h"
- #import "KeepVCSingleton.h"
- #import "SettingsViewController.h"
- #import "MFSideMenu.h"
- #import "SettingNavigationViewController.h"
- #import <QuartzCore/QuartzCore.h>
- NSString * const NOTIF_offlineModeEdited =@"offlineModeEdited";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- * offlineModeEdited
- *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- @interface LeftSideMenuViewController ()
- @property (nonatomic, strong) NSMutableArray *menuItems;
- @end
- @interface LeftSideMenuViewController (private)
- - (void)offlineModeEdited:(NSNotification *)notif;
- @end
- @implementation LeftSideMenuViewController
- @synthesize delegate;
- - (void)awakeFromNib
- {
- self.menuItems = [NSMutableArray arrayWithObjects:@"Events", @"Documents", @"Calendar",@"Offline Mode",nil];
- KeepVCSingleton *shrd= [KeepVCSingleton sharedInstance];
- shrd.leftVc=self;
- }
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- //background image
- // self.view.backgroundColor= [UIColor clearColor];
- // self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"menu_background.png"]];
- [self.tableView setBackgroundView:nil];
- self.tableView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"menu_background.png"]];
- //background image
- //self.view.backgroundColor= [UIColor clearColor];
- //self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Backgroundwithout Logo.png"]];
- //self.tableView.backgroundColor=nil;
- // Register observer to be called when logging out
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(offlineModeEdited:)
- name:NOTIF_offlineModeEdited object:nil];
- //[self testOfflineOption];
- }
- - (void)offlineModeEdited:(NSNotification *)notif{
- NSLog(@"offlineModeEdited: recieved");
- //[self testOfflineOption];
- }
- //Checks if we have an internet connection or not
- - (void)testOfflineOption
- {
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OfflineMode"]==NO) {
- [self dismissOfflineMode];
- }
- else
- {
- [self showOfflienMode];
- }
- }
- -(void) showOfflienMode
- {
- //maybe animation while adding row?
- if (![self.menuItems containsObject:@"Offline Mode"]){
- [self.menuItems addObject:@"Offline Mode"];
- }
- [self.tableView reloadData];
- }
- -(void)dismissOfflineMode
- {
- if ([self.menuItems containsObject:@"Offline Mode"]) {
- [self.menuItems removeObject:@"Offline Mode"];
- }
- [self.tableView reloadData];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (section==0) {
- return [self.menuItems count];
- }
- else
- return 1;
- }
- // set header height of gropued tableview
- -(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section {
- if (section==0) {
- return 80;
- }
- else
- return 120;
- }
- //row height
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 110.0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *cellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleGray;
- UIFont* rightFont =[UIFont fontWithName:@"Gill Sans" size:14];
- UIColor* rightColor = [UIColor whiteColor];
- UILabel *hasInvitedYouText=[[UILabel alloc] initWithFrame:CGRectMake(5.0f, 75.0f, 195.0f, 25.0f)];
- hasInvitedYouText.font=rightFont;
- hasInvitedYouText.textColor=rightColor;
- hasInvitedYouText.backgroundColor=[UIColor clearColor];
- hasInvitedYouText.textAlignment=UITextAlignmentCenter;
- UIImageView *menuImageView;
- UIImage *menuImage;
- if (indexPath.section==0) {
- hasInvitedYouText.text = [self.menuItems objectAtIndex:indexPath.row];
- switch (indexPath.row) {
- case 0:
- menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(50.0f, 20.0f,47.0f, 69.0f)];
- menuImage=[UIImage imageNamed:@"events_icon.png"];
- break;
- case 1:
- menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(33.0f, 20.0f,82.0f, 68.0f)];
- menuImage=[UIImage imageNamed:@"document_icon.png"];
- break;
- case 2:
- menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(40.0f, 20.0f,68.0f, 68.0f)];
- menuImage=[UIImage imageNamed:@"calendar_icon.png"];
- break;
- case 3:
- menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(30.0f, 20.0f,92.0f, 71.0f)];
- menuImage=[UIImage imageNamed:@"offline_icon.png"];
- break;
- default:
- break;
- }
- // cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row];
- }
- else{
- menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(50.0f, 20.0f,58.0f, 71.0f)];
- hasInvitedYouText.text = @"Settings";
- menuImage=[UIImage imageNamed:@"settings_icon.png"];
- }
- menuImageView.image=menuImage;
- [cell.contentView addSubview:menuImageView];
- [hasInvitedYouText sizeToFit];
- //[cell.contentView addSubview:hasInvitedYouText];
- // cell.backgroundColor = [UIColor clearColor];
- // cell.layer.backgroundColor = [UIColor clearColor].CGColor;
- //
- // [[cell imageView] setBackgroundColor:[UIColor clearColor]];
- // [cell setBackgroundColor:[UIColor clearColor]];
- // [self.tableView setBackgroundView:nil];
- cell.textLabel.text=nil;
- return cell;
- }
- //transparentcells
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- cell.backgroundColor = [UIColor clearColor];
- }
- //transparent headers
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIImage *myImage = [UIImage imageNamed:@""];
- UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
- imageView.frame = CGRectMake(10,10,300,100);
- return imageView;
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Return NO if you do not want the specified item to be editable.
- return NO;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- //this sends object info to detail
- if (indexPath.section==0) {
- [delegate changeTab:indexPath.row];
- }
- else{
- [self settingPopOverControl];
- }
- //deselect selected row
- [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
- }
- //call settings form sheet viewcontroller
- -(void)settingPopOverControl
- {
- UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
- SettingNavigationViewController *settingsVC = [sb instantiateViewControllerWithIdentifier:@"SettingNavigation"];
- //add navigation controller
- // UINavigationController *modalViewNavController= [[UINavigationController alloc] initWithRootViewController:settingsVC];
- // modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
- // modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;
- // [self presentModalViewController:modalViewNavController animated:YES];
- //added navigation controller in storyboard no need to create it programmatically again
- settingsVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
- settingsVC.modalPresentationStyle = UIModalPresentationFormSheet;
- [self presentModalViewController:settingsVC animated:YES];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement