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