我试图从主窗口中将登录窗口显示为工作表,但是每当尝试实现AppKit方法时,都会由于各种无法区分的原因而弹出错误。
当我将他们的代码/改编的类应用于自己的项目时,这些在线指南都无法正常工作。
大多数指南已过时,包括Apple文档。而且它们似乎都与自动引用计数不兼容。或Xcode 4接口(interface)。
有人能够为我提供完整的指南,这是在MainWindow上按下按钮后显示表格的最简单方法。
如果需要,请随时询问更多信息。
最佳答案
Xcode 4教程
创建新项目,并将以下内容添加到AppDelegate.h
和AppDelegate.m
。
AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet NSPanel *theSheet;
}
@property (assign) IBOutlet NSWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
- (IBAction) showTheSheet:(id)sender {
[NSApp beginSheet:theSheet
modalForWindow:(NSWindow *)_window
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
}
-(IBAction)endTheSheet:(id)sender {
[NSApp endSheet:theSheet];
[theSheet orderOut:sender];
}
@end
打开
MainMenu.xib
。使用现有的
NSWindow
。使用以下按钮使其可见:
创建一个新的
NSPanel
。添加适当的
NSButtons
。将
Close
连接到App Delegate
。然后选择
endTheSheet
。将
Open
连接到App Delegate
。然后选择
showTheSheet
。将
App Delegate
连接到新的NSPanel
。然后选择
theSheet
。选择
NSPanel
并禁用Visible At Launch
。(必要步骤!)
现在点击运行并享受结果:
关于cocoa - 使用ARC在Xcode 4(OSX 10.7.2)中将 cocoa 窗口显示为工作表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8058653/