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