2013-11-03 5 views
0

예상대로 작동하는 UINavigationController 오른쪽에 두 개의 단추가 있습니다. 다음 코드를 사용하면이 문제를 해결할 수 있습니다.배열에서 UINavigation 단추 비활성화

// Share Button 
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[shareButton setFrame:CGRectMake(0,0,19,21)]; 
[shareButton addTarget:self action:@selector(shareButton) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *shareBarButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareButton)] autorelease]; 
shareBarButton.tintColor = [UIColor whiteColor]; 

// Snapback Button 
UIButton *navSnapbackButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[navSnapbackButton setFrame:CGRectMake(0,0,26,21)]; 
[navSnapbackButton setImage:[UIImage imageNamed:@"Snapback.png"] forState:UIControlStateNormal]; 
[navSnapbackButton addTarget:self action:@selector(snapbackButton) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *navSnapbackBarButton = [[[UIBarButtonItem alloc] initWithCustomView:navSnapbackButton] autorelease]; 
navSnapbackButton.tintColor = [UIColor whiteColor]; 

// Right Toolbar Button Setup 
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:navSnapbackBarButton, shareBarButton, nil]]; 

나는이 배열의 버튼을 어떻게 비활성화합니까? 예를 들어 특정 조건에서 Share 버튼을 사용하지 않도록 설정했다면 어떻게해야합니까? 미리 감사드립니다! 대신 당신의 UIBarButtonItem * shareBarButton에 대한 지역 변수의

답변

0

, 당신은 다른 방법으로 그것에 접근이 있도록 @interface 섹션에서 속성으로 선언 :

@property (강한 비 원자) UIBarButtonItem * shareBarButton을 ;

...

그럼 당신이했던 것처럼 툴바의 설치 루틴에 할당 :

// 공유 버튼

shareBarButton = [[UIBarButtonItem ALLOC] initWithBarButtonSystemItem : UIBarButtonSystemItemAction 대상 : 자기 행동을 : @ 선택기 (shareButton :)];

shareBarButton.tintColor = [UIColor whiteColor]; (ID) 송신기 {

}

...

- (무효) shareButton

:

이 ...의 버튼

동작은 다음과 같다 그런 다음 shareButton 액션이나 다른 메소드에서 enabled 속성을 설정할 수 있습니다 :

self.shareBarButton.enabled = NO;

경우 (...) {

self.shareBarButton.enabled = YES;

}

0

앤 테일러의 대답은 내가 그런 식으로 할 것입니다,하지만 당신은 당신의보기에서 인터페이스 속성 등이 UIBarButton을하지 않으려면, 당신이 할 수있는 아주 좋은입니다 :

- (void)performAction:(id)sender 
{ 
    NSArray *_barButtons = self.navigationItem.rightBarButtonItems; 
    UIBarButtonItem *_barButton; 
    for (_barButton in _barButtons) { 
    if (_barButton.tag == 0) { 
     _barButton.enabled = NO; 
    } 
    } 
} 

I.

:
UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(performAction:)]; 
btn1.tag = 0; 
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"_ui_image"] style:UIBarButtonItemStylePlain target:self action:@selector(performAction:)]; 
btn2.tag = 1; 
self.navigationItem.rightBarButtonItems = @[btn1,btn2]; 

그리고 장애인 방법

관련 문제