gpt4 book ai didi

objective-c - 多窗口 Mac 应用程序

转载 作者:行者123 更新时间:2023-12-03 17:23:13 25 4
gpt4 key购买 nike

我想制作一个多窗口 Mac 应用程序,但我被多窗口部分困住了!

我可以通过创建 xib 文件并使用此方法来显示一些窗口:

-(void)popView:(NSString *)viewName {
_windowController = [[AddProdutWindowController alloc] initWithWindowNibName:viewName];
[_windowController showWindow:nil];
}

@property(强,非原子)AddProdutWindowController *windowController;

在我的头文件中,AddProductViewController继承自NSWindowViewController

我已将 Xcode 中的 NSViewController 子类链接到我的 xib 文件。

现在我想将一些数据发送到我的新 View 并在一些 NSTextField 中显示它们,但我不知道如何做到这一点!

我对 WindowsControllerViewController 非常困惑,我不完全知道如何/在哪里使用它们。

感谢您的帮助。

最佳答案

试试这个:

你的firstWindowController.h:

#import <Cocoa/Cocoa.h>
@class SecondWindowController;

@interface ResultWindowController : NSWindowController{
SecondWindowController *swc;
}
@property (assign) NSNumber *xyz;
...

你的第一个WindowController.m:

#import "FirstWindowController.h"
#import "SecondWindowController.h"

@implementation FirstWindowController
@synthesize xyz;


- (IBAction)openSecondWindow:(id *)sender {
if (!swc)
{
swc = [[SecondWindowController alloc] init];
}
[Swc setFwc:self];
[Swc showWindow:self];

你的第二个WindowController.h:

#import <Cocoa/Cocoa.h>
@class FirstWindowController;
@interface SecondWindowController : NSWindowController {
FirstWindowController *fwc;
}
@property (retain) IBOutlet FirstWindowController *fwc;

@end

你的第二个WindowController.m:

#import "SecondWindowController.h"
#import "FirstWindowController.h"

@implementation SecondWindowController
@synthesize fwc;


- (id)init
{
if(![super initWithWindowNibName:@"SecondWindow"])
return nil;
NSLog(@"_init: %@", NSStringFromClass([self class]));

return self;
}

- (void)windowDidLoad
{
[super windowDidLoad];

NSLog(@"swc didload self=%p", self); //thats your second window controller

NSLog(@"fwc value is %@", fwd.xyz); // here you should be able to see the value from FirtsWindowController
}

关于objective-c - 多窗口 Mac 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962044/

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