2016-11-24 57 views
3

我使用在我的IOS應用pagemenu鑑於follwing此https://github.com/uacaps/PageMenupagemenu導航右欄按鈕項(不能根據凸片隱藏)

在menuviewcontroller我具有其中在左側我有一個導航條slidemenu按鈕,右邊我有欄按鈕項(被稱爲這是我在storybord加選照片)

下面的導航欄我加入pagemenu視圖4片(含病人,EMR,聊天,處方)

所以根據竊聽我想隱藏/顯示欄按鈕項目(這意味着只爲我想要顯示的EMR選項卡該欄按鈕項(選擇照片),否則我想隱藏(用於佈雷3個標籤),但我不能達到它 這是我在menuviewcontroller viewDidLoad方法enter 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]; 

} 

看到屏幕截圖我連着

代碼

,所以我想隱藏的除了EMR標籤 的viewDidLoad中的所有標籤右側導航欄按鈕和viewwill出現在menuviewcontroller方法只調用一次,那些不要求每敲擊菜單時(患者,EMR,聊天,處方)所以我不知道如何實現它 請任何人幫我在這

在此先感謝

這在這個問題上

添加此行

pagingMenuViewController.delegate=self; 

對象(pagingMenuViewController)後,對我的作品作爲公認的答案發起的類似下面

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; 

,我加了這個代表 CAPSPageMenuDele門 ANSD委託方法

- (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]; 
    } 
} 
+0

由於拉維基蘭和Durai Amuthan.H –

回答

2

在viewDidLoad方法中添加

_pagingMenuView.delegate = self 

然後實現委託方法

- (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 
    } 

} 
+0

感謝您的答覆 –

+0

我已經試過代碼,但是當我改變didMoveToPage方法不調用標籤有沒有其他錯誤? –

+0

是否爲你添加了

2

確保您創建實例後分配委託財產

_pagingMenuView.delegate = self 

其餘的隱藏,顯示您可能在代理方法中處理的業務

1

@sathya chinnasamy它只是沒有。你可以在這裏使用NSNotificationCenter。

//粘貼此代碼導航欄類

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playerStatus:) name:@"hideNavigationButton" object:nil]; 

- (void) playerStatus:(NSNotification *) notification 
{ 
// hide navigation button. 
} 

//When you tap the button call this method 

[[NSNotificationCenter defaultCenter]postNotificationName:@"hideNavigationButton" object:nil]; 
+0

希望這個幫助。 – Raja