2011-04-05 37 views
0

我有两个类,firstView & secondView。 在firstView.h在可可Mac上创建新窗口的问题点击按钮

 
#import "SecondView.h" 
#import "FirstView" 


@interface FirstView : NSObject { 

    IBOutlet NSButton *test; 
    secondView *mySecond; 
} 

@property (nonatomic, retain) IBOutlet NSButton *test; 


-(IBAction) buttonClicked:(id)sender; 

@end 

在firstView.m

 
#import "FirstView.h" 


@implementation FirstView 
@synthesize test; 


-(IBAction) buttonClicked:(id)sender{ 

    NSLog(@"HELLO!!!"); 
    if (!mySecond) { 
     // If the second view controller doesn't exist yet, make it! 
     mySecond = [[secondView alloc] init]; 
    } 
    [mySecond displayWindow]; 
} 

@end 

在secondView.h

 
#import 


@interface SecondView : NSObject { 

    IBOutlet NSWindow *progressWindow; 
    IBOutlet NSButton *testNew; 
} 

@property (nonatomic, retain) IBOutlet NSButton *testNew; 

- (void)displayWindow; 

-(IBAction) buttonClickedNew:(id)sender; 

@end 

在secondView.m

 
#import "SecondView.h" 


@implementation SecondView 
@synthesize testNew; 

- (id)init { 

    if (self = [super init]) { 
     NSLog(@"HAI!!"); 

     [NSBundle loadNibNamed:@"Next" owner:self]; 
    } 
    return self; 

} 

- (void)displayWindow { 

    if (![progressWindow isVisible]) { 
     NSLog(@"ON SECOND!!!"); 
     [progressWindow setIsVisible:YES]; 
     [progressWindow orderFront:nil];   
    } 

} 

-(IBAction) buttonClickedNew:(id)sender { 

    NSLog(@"GOOD!!!"); 
} 

@end 

但我得到的输出为...

 
Running… 
2011-04-05 16:12:30.400 toDoListMac[6558:a0f] HELLO!!! 
2011-04-05 16:12:30.402 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.404 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.406 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.408 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.409 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.410 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.411 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.413 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.414 toDoListMac[6558:a0f] HAI!! 
2011-04-05 16:12:30.415 toDoListMac[6558:a0f] HAI!! 

secondView'init'正在调用无限次! 请..请帮助我.....

我想要做的是...我想打开另一个特定的动作xib /窗口,说按钮点击....请帮我...

回答

0

有一个控制可可中的窗口的类:NSWindowController你为什么不使用它?通过子类化NSWindowController可以获得所有的细节,然后你只需要添加特定于你的用例的方法。简单得多。

此外,还不清楚这些是单独的窗口还是单独的视图。如果后者,你想调查NSViewController