在Xcode 4(OSX 10.7.2)中使用ARC显示Cocoa窗口作为表 [英] Displaying a Cocoa Window as a Sheet in Xcode 4 (OSX 10.7.2) with ARC

查看:219
本文介绍了在Xcode 4(OSX 10.7.2)中使用ARC显示Cocoa窗口作为表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个登录窗口显示为一个工作表从我的MainWindow,但每当我尝试实现AppKit方法时,错误总是弹出各种不可区分的原因。

I'm trying to get a Login Window to display as a sheet from my MainWindow, but whenever I try to implement the AppKit methods an error always pops up for various indistinguishable reasons.

没有在线指南有工作,当我将他们的代码/适应类应用于我自己的项目,他们从来没有工作。

None of the online guides out there are working, when i apply their code / adapted classes to my own project they never work.

大多数指南都过时了,包括Apple文档。它们都不能与自动引用计数兼容。或者Xcode 4接口。

Most of the guides are heavily outdated, including the Apple Documentation. And none of them seem to be compatible with Automatic Reference Counting. Or the Xcode 4 interfaces.

有人能够为我提供完整的指南,为在MainWindow上按下按钮后显示工作表的最简单的方法。

Would someone be able to detail for me in full a guide, for the simplest way of displaying a sheet following a button press on the MainWindow.

如果需要,可随时询问更多信息。

Feel free to ask for more information if you need it.

推荐答案

p> Xcode 4教程

创建新项目并将以下内容添加到 AppDelegate.h AppDelegate.m

Create new project and add the following to AppDelegate.h and AppDelegate.m.

AppDelegate.h

AppDelegate.h

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate> {

    IBOutlet NSPanel *theSheet;
}

@property (assign) IBOutlet NSWindow *window;

@end

AppDelegate.m

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

它使用以下按钮显示:

Open the MainMenu.xib.
Use the existing NSWindow.
Make it visible using the following button:

创建一个新 NSPanel

添加相应的 NSButtons

连接关闭到 App Delegate

并选择 endTheSheet

连接打开到< c $ c> App Delegate

并选择 showTheSheet

App Delegate 连接到新 NSPanel

并选择 theSheet

选择 NSPanel 并禁用可见启动
(必要步骤!)

Select the NSPanel and disable Visible At Launch. (Essential step!)

现在点击运行并享受结果:

Now hit run and enjoy the result:

这篇关于在Xcode 4(OSX 10.7.2)中使用ARC显示Cocoa窗口作为表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆