2011-04-05 48 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

相關問題