2012-12-03 28 views
0

Mac OS X NSTabView:如何显示用于键盘导航的TabItem视图?带有NSTabView键盘的Mac OS X NSPanel事件:如何使用NSTabViewDelegate显示TabItem的View for keyboard navigation?

我有一个TabView,用鼠标工作得很好。我想让NSTabView支持键盘导航。

使用箭头键移动各种TabItems,但不会导致显示TabItem视图到 。我需要点击标签才能显示标签的视图。

当箭头键被使用时,NSTabViewDelegate方法

tabView:shouldSelectTabViewItem: 

被调用并返回YES。没有其他NSTabViewDelegate方法被调用,因此其视图不会显示。

使用键盘达到TabItem时触发鼠标(显示视图)行为的最佳方式/推荐方式是什么?这可以修复在Xcode 或我必须涉及子类和/或通知吗?

回答

0

内MyAppController(主窗口)的应用程序最初使用此代码忍受editRecipeController的窗口,一个NSPanel

推出EditWindow如纸

[NSApp beginSheet:[editController window] modalForWindow:[self window] modalDelegate:nil didEndSelector:nil contextInfo:nil]; 
    [NSApp runModalForWindow:[editController window]]; 
    // sheet is up here... 
    [NSApp endSheet: [editController window]]; 
    [[editController window] orderOut:nil]; 
    [[editController window] close]; 

窗口内,一//原始代码NSPanel,有一个NSTabView。 面板完全使用鼠标功能。它有一个五个Tab NSTabView。一个选项卡具有NSTextField,三个选项卡具有NSTextView。第五个有一个NSTableView。

我的问题是如下,在使用ArrowKey, 正确的选项卡被突出显示从标签导航到选项卡上的用户,但并没有成为“选择”,也就是说,没有 显示视图。使视图出现的唯一方法是用鼠标单击Tab。

My goal is to have full keyboard support for the NSTabView 

我能够按照获得的NSTabView正确的行为: Hillegass'书,第25章,“表

// MyAppController.m - WindowController for mainWindow 

    - (IBAction) editRecipeAction:(id)sender { 
     // setup the edit sheet controller if one hasn't been setup already 
     if (editRecipeController == nil){ 
      editRecipeController = [[EditRecipeController alloc] initWithWindowNibName:@"EditRecipe"]; 
      //[editRecipeController setMyAppController:self]; 
     } 

     [[NSApplication sharedApplication] beginSheet:editRecipeController.window 
        modalForWindow:self.window 
         modalDelegate:editRecipeController 
        didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) 
         contextInfo:nil]; 
    } 

//结束MyAppController.m

// EditRecipeController.m

- (IBAction)cancel:(id)sender 
    { 

     [NSApp endSheet:self.window returnCode:0 ] ; 
     [self.window orderOut:self]; 
    } 

- (void) sheetDidEnd:(NSWindow *) sheet returnCode:(int)returnCode contextInfo:(void *) contextInfo { 

    DLog(@"sheet=%@",sheet); 

} 

如果您的目标是全键盘支持对于这样的NSTabView,我想你需要一些东西 ,比如下面的使用NSTabViewDelegate方法:

- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem{ 

     NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; 
     [f setNumberStyle:NSNumberFormatterDecimalStyle ]; 
     NSNumber *tabNumber = 
     [f numberFromString:tabViewItem.identifier]; 
     [f release]; 

     switch (tabNumber.integerValue) { 
      case 1: 
       editRecipeController.tabView.nextKeyView = editRecipeController.textViewIngredients; 
       editRecipeController.textViewIngredients.nextKeyView = editRecipeController.cancelButton; 
       editRecipeController.cancelButton.nextKeyView = editRecipeController.doneButton; 
       editRecipeController.doneButton.nextKeyView = editRecipeController.tabView; 
       break; 
      case 2: 
       editRecipeController.tabView.nextKeyView = editRecipeController.textViewDirections; 
       editRecipeController.textViewDirections.nextKeyView = editRecipeController.cancelButton; 
       editRecipeController.cancelButton.nextKeyView = editRecipeController.doneButton; 
       editRecipeController.doneButton.nextKeyView = editRecipeController.tabView; 
       break; 
      case 3: 
       editRecipeController.tabView.nextKeyView = editRecipeController.textViewDirections; 
       editRecipeController.textViewDirections.nextKeyView = editRecipeController.cancelButton; 
       editRecipeController.cancelButton.nextKeyView = editRecipeController.doneButton; 
       editRecipeController.doneButton.nextKeyView = editRecipeController.tabView; 
       break; 
      case 4: // Comments 
       editRecipeController.tabView.nextKeyView = editRecipeController.textViewComments; 
       editRecipeController.textViewComments.nextKeyView = editRecipeController.cancelButton; 
       editRecipeController.cancelButton.nextKeyView = editRecipeController.doneButton; 
       editRecipeController.doneButton.nextKeyView = editRecipeController.tabView; 
       break; 
      case 5: //Categories - Table can not be edited 
       editRecipeController.tabView.nextKeyView = editRecipeController.cancelButton; 
       editRecipeController.cancelButton.nextKeyView = editRecipeController.doneButton; 
       editRecipeController.doneButton.nextKeyView = editRecipeController.tabView; 
       break; 
      default: 
       DLog(@"switch value error"); 
       break; 
     }// end switch 

    } 
相关问题