gpt4 book ai didi

objective-c - 2 年前的代码现在不起作用(WindowController alloc)

转载 作者:行者123 更新时间:2023-12-03 17:11:06 24 4
gpt4 key购买 nike

下面的代码在 2 年前运行

今天我尝试重建

AppDelegate.h

#import <Cocoa/Cocoa.h>
#include <stdio.h>
#include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h>

@class EnterWindowController;


@interface AppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;

EnterWindowController *vEnterWindowController;

}

@property (retain,nonatomic) EnterWindowController *vEnterWindowController;


@end

AppDelegate.m

#import "AppDelegate.h"
#include <stdio.h>
#include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h>

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#import "EnterWindowController.h"

@implementation AppDelegate;
@synthesize vEnterWindowController;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

if(!vEnterWindowController)
{


vEnterWindowController=[[EnterWindowController alloc] init];

}


[vEnterWindowController showWindow:self];//point A
}

与EnterWindowController相关的enterwidow不显示,我在A处设置断点,发现vEnterWindowController为nil,看起来像

 vEnterWindowController=[[EnterWindowController alloc] init]; 

不起作用并且总是返回nil。

欢迎您发表评论

最佳答案

此语法适用于使用 Xcode 6.1 的我:

if (!vEnterWindowController)
{
vEnterWindowController = [[EnterWindowController alloc] initWithWindowNibName:@"yourWindowNibName"];
}

[vEnterWindowController showWindow:self];

顺便说一句,您也可以在 .h 文件中使用

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <AppKit/AppKit.h>

@interface AppDelegate : NSObject <NSApplicationDelegate, , NSWindowDelegate> {

@public

EnterWindowController *vEnterWindowController;
}
@property (assign) IBOutlet NSWindow *window;

并且您不需要合成vEnterWindowController。您也不需要在 .m 文件中合成窗口。

NSWindowDelegate 协议(protocol)添加到 AppDelegate 还可以方便地接收有关主窗口的通知。

关于objective-c - 2 年前的代码现在不起作用(WindowController alloc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27966169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com