sathya chinnasamy sathya chinnasamy - 14 days ago 5
iOS Question

pagemenu-navigation Right bar button item(cannot hide according to tabs)

I am using pagemenu view in my ios app by follwing this https://github.com/uacaps/PageMenu

In a menuviewcontroller I am having a navigation bar in which at left side I have slidemenu button and right side I have bar button item(called select photo which I added in storybord)

Below that navigation bar I am adding pagemenu view 4 tab( contains patient, EMR, chat, prescription)

so according to tapping I want to hide/show that bar button item(that means only for EMR tab I want to show the bar button item(select photo) otherwise I want to hide( for remining 3 tabs),but I cannot achieve it
this is my code in that menuviewcontroller viewdidload methodenter image description here

- (void)viewDidLoad {
[super viewDidLoad];


SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self->_slideOutMenu setTarget: self.revealViewController];
[self->_slideOutMenu setAction: @selector( revealToggle: )];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

}

self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};



UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
Patient* controller1 = [sb instantiateViewControllerWithIdentifier:@"patient"];

controller1.title = @"PATIENT";

EMR* controller2 = [sb instantiateViewControllerWithIdentifier:@"emr"];

controller2.title = @"EMR";
Chat* controller3 = [sb instantiateViewControllerWithIdentifier:@"chatViewcontroller"];

controller3.title = @"CHAT";

Prescription* controller4 = [sb instantiateViewControllerWithIdentifier:@"prescription"];

controller4.title = @"PRESCRIPTION";

NSArray *controllerArray = @[controller1, controller2, controller3, controller4];
NSDictionary *parameters = @{
CAPSPageMenuOptionScrollMenuBackgroundColor: [UIColor colorWithRed:60.0/255.0 green:169.0/255.0 blue:128.0/255.0 alpha:1.0],
CAPSPageMenuOptionViewBackgroundColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
CAPSPageMenuOptionSelectionIndicatorColor: [UIColor whiteColor],
CAPSPageMenuOptionBottomMenuHairlineColor: [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:70.0/255.0 alpha:1.0],
CAPSPageMenuOptionMenuItemFont: [UIFont fontWithName:@"HelveticaNeue" size:12.0],
CAPSPageMenuOptionMenuHeight: @(70.0),
CAPSPageMenuOptionMenuItemWidth: @(120.0),
CAPSPageMenuOptionCenterMenuItems: @(YES)
};

_pagingMenuView = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 42.0, self.view.frame.size.width, self.view.frame.size.height-38) options:parameters];
if (_currentIndex >= 0 && _currentIndex <= 2){


[_pagingMenuView moveToPage:_currentIndex];

}
[self.view addSubview:_pagingMenuView.view];

}


see the screen shot i attached

so i want to hide that right navigation bar button for all tabs except emr tab
the viewdidload and viewwill appear methods in menuviewcontroller is called only once , those are not calling every time tapping the menus(patient, EMR, chat, prescription) so i donnot know how to acheive it
please any one help me on this

thanks in advance

This works for me as accepted answer in this question

Adding this line

pagingMenuViewController.delegate=self;


after the object (pagingMenuViewController) intiated like below

pagingMenuViewController = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 42.0, self.view.frame.size.width, self.view.frame.size.height-38) options:parameters];
self.navigationItem.rightBarButtonItem.tintColor=[UIColor clearColor];

pagingMenuViewController.delegate=self;


and i added this delegate
CAPSPageMenuDelegate
ansd delegate methods

- (void)didMoveToPage:(UIViewController *)controller index:(NSInteger)index {
if(index ==1){
[self show];
}else{
[self hide];
}
}
- (void)willMoveToPage:(UIViewController *)controller index:(NSInteger)index{
if(index ==1){
[self show];
}else{
[self hide];
}
}

Answer

In viewDidLoad method add

_pagingMenuView.delegate = self

then implement the delegate method

- (void)didMoveToPage:(UIViewController *)controller index:(NSInteger)index {
    if(index ==1){
        self.navigationItem.rightBarButtonItem = //your barButton to select photo
        self.navigationItem.leftBarButtonItem = nil;
    }else{
        self.navigationItem.rightBarButtonItem = nil;
        self.navigationItem.leftBarButtonItem = //your barButton to reveal the slide menu
    }

}