2010-12-17 7 views
5

나는 이상한 행동을하고있다. 응용 프로그램이 일부 정보를 기다리고있을 때 사용자에게 보여줄 텍스트가있는 패널을 사용하고 있습니다. 이 패널은 사용자가 무언가를 클릭하는 것을 방지하기 위해 모달로 표시됩니다.NSToolBar 유효성 검사를 강제 적용하는 방법?

로딩 패널이 숨겨지면 도구 모음의 모든 항목이 비활성화되고 validateToolbarItem 메서드가 호출되지 않습니다.

- (void)showInWindow:(NSWindow *)mainWindow { 
sheetWindow = [self window]; 
[self sheetWillShow]; 

[NSApp beginSheet:sheetWindow modalForWindow:mainWindow modalDelegate:nil didEndSelector:nil contextInfo:nil]; 
[NSApp runModalForWindow:sheetWindow]; 
[NSApp endSheet:sheetWindow]; 
[sheetWindow orderOut:self]; 
} 

- (void)dismissModal { 
[sheetWindow close]; 
[NSApp stopModal]; 
} 

가 어떻게이 경우에는 유효성을 검사하는 도구 모음을 강제 할 수

나는 이런 방식으로 패널을 보여주는거야? 코멘트 후

편집 :

난 이미 시도 :

  • [[[NSApp mainWindow] toolbar] validateVisibleItems]
  • [[NSApp mainWindow] update];
  • [NSApp updateWindows];
  • [NSApp setWindowsNeedUpdate:YES];

모두 dismissModal입니다. 나는

답변

3
NSToolbar *toolbar; //Get this somewhere. If you have the window it is in, call [window toolbar]; 
[toolbar validateVisibleItems]; 
+0

헤더에서 : 일반적으로이 메소드를 호출하면 안됩니다. 이 메서드는 가시 항목 각각 의 유효성을 검사하기 위해 창 업데이트에서 호출됩니다. –

6

문제는 NSToolbar는 NSToolbarItem의 내 것도 없었다 이미지 타입의 것을에 확인 메시지를 전송하는 것입니다 .... 문제는 다른 곳에 있다고 생각하고있다. NSToolbarItems의 일부 또는 전체를 확인하려면 NSToolBar의 사용자 정의 하위 클래스를 만들고 validateVisibleItems : 메서드를 재정의합니다. 그러면 모든 유효한 NSToolbarItem에 유효성 확인 메시지가 전송됩니다. 유일한 차이점은 반환 된 BOOL을 사용하여 툴바 클래스에서 항목을 활성화 또는 비활성화하는 대신 유효성 검사 메소드 자체에서 항목을 활성화 또는 비활성화해야한다는 것입니다.

- (IBAction)backButton:(NSSegmentedControl*)sender 
{ 
    NSInteger segment = sender.selectedSegment; 
    if (segment == 0) 
    { 
     // Action for first button segment 
    } 
    else if (segment == 1) 
    { 
     // Action for second button segment 
    } 
} 

장소는 툴바 항목의 작업을 처리하는 동일한 컨트롤러에서 다음과 같은 : : 이제

@interface CustomToolbar : NSToolbar 
@end 
@implementation CustomToolbar 
-(void)validateVisibleItems 
{ 
    for (NSToolbarItem *toolbarItem in self.visibleItems) 
    { 
     NSResponder *responder = toolbarItem.view; 
     while ((responder = [responder nextResponder])) 
     { 
      if ([responder respondsToSelector:toolbarItem.action]) 
      { 
       [responder performSelector:@selector(validateToolbarItem:) withObject:toolbarItem]; 
      } 
     } 
    } 
} 
@end 

, 당신은 당신의 도구 모음에 NSSegmentedControl에 대한 작업을 처리하는 IBAction를 방법과 컨트롤러가 가정

-(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem 
{ 
    SEL theAction = [toolbarItem action]; 
    if (theAction == @selector(backButton:)) 
    { 
     [toolbarItem setEnabled:YES]; 

     NSSegmentedControl *backToolbarButton = (NSSegmentedControl *)toolbarItem.view; 
     [backToolbarButton setEnabled:YES forSegment:0]; 
     [backToolbarButton setEnabled:NO forSegment:1]; 
    } 
    return NO; 
} 

결과적으로 사용 또는 사용 중지 된 세그먼트를 완벽하게 제어 할 수 있습니다.

이 기술은 아이템의 수신 액션이 리스폰 더 체인의 컨트롤러에 의해 처리되는 한, 거의 모든 다른 유형의 NSToolbarItem에 적용되어야합니다.

이 정보가 도움이되기를 바랍니다.

+0

답변 해 주셔서 감사합니다! 그것은 유망한 것으로 보인다 :) 당신이이 질문을 보는 것은 상당히 오래된 것입니다. 나는 어떤 OSX 프로젝트에서 더 이상 일하고 있지 않다. 그래서 당신이 당신의 대답을 유효하게 할 수있는 사람이 있다면 나는 그것을 올바른 것으로 표시 할 것이다. 감사합니다 –

+0

감사.그런 오래된 질문에 다소 어색한 대답을 느꼈지만 솔루션을 찾기 위해 많은 노력을 기울였습니다. 마침내 몇 가지 개념을 거대한 진흙탕이 아닌 무언가로 이어 붙인 다음, 나는 그것을 공유하는 것이 좋은 생각이라고 생각했습니다. 나는 그것이 효과가있다는 것을 알고 있지만, 내가 더 알고 싶은 것은 더 나은 해결책이 있는지 또는 내가 적절하다고 생각하지 않는 것을했을 때입니다. –

관련 문제