0

Я хочу создать приложение для Mac с несколькими окнами, и я застрял в нескольких частях окна!Приложение для нескольких окон Mac

Я могу показать некоторые окна, создав файл XIb и с помощью этого метода:

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

С @property (strong, nonatomic) AddProdutWindowController *windowController;

в моем файле заголовка и AddProductViewController наследование от NSWindowViewController

Я связала подкласс NSViewController в Xcode к моему файлу xib.

Теперь я хочу отправить некоторые данные в свой новый вид и показать их в каком-то NSTextField, и у меня нет ни единой подсказки, как это сделать!

Я очень смущен WindowsController и ViewController, я точно не знаю, как их использовать.

Благодарим за помощь.

ответ

0

Попробуйте это:

ваш firstWindowController.h:

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

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

ваш firstWindowController.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]; 

ваш secondWindowController.h:

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

@end 

ваш secondWindowContr oller.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 
} 
Смежные вопросы