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 /窗口,說按鈕點擊....請幫我...