【问题标题】:Multiple windows mac application多个windows mac应用程序
【发布时间】:2013-02-19 16:10:42
【问题描述】:

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

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

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

@property (strong, nonatomic) AddProdutWindowController *windowController;

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

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

现在我想将一些数据发送到我的新视图并在NSTextField 中显示它们,但我不知道该怎么做!

我对@9​​87654328@ 和ViewController 很困惑,我不知道如何/在哪里使用它们。

感谢您的帮助。

【问题讨论】:

    标签: objective-c macos cocoa nswindowcontroller nsviewcontroller


    【解决方案1】:

    试试这个:

    你的第一个WindowController.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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      • 2012-06-17
      • 2018-12-27
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多