在 MyAppController (mainWindow) 中,应用程序最初使用此代码来放置 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];
在 Window 内部,一个 NSPanel,有一个 NSTabView。使用鼠标,面板功能齐全。它有一个五个选项卡 NSTabView。一个 Tab 有一个 NSTextField,三个 Tab 有一个 NSTextView。第五个有一个 NSTableView。
我遇到的问题如下,当用户使用箭头键从一个选项卡导航到另一个选项卡时,正确的选项卡被突出显示,但没有被“选中”,也就是说,它的视图没有显示。使视图出现的唯一方法是用鼠标单击选项卡。
My goal is to have full keyboard support for the NSTabView
我能够通过以下方式获得 NSTabView 的正确行为: Hillegass' Book , Chapter 25, "Sheets.
// 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
// 编辑配方控制器.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
}