メインウィンドウにいくつかのボタンがある Mac アプリケーションを作成しています。
ボタンをクリックするDetailWindow
と、NSTableviewで開きます。すべてのボタンクリックイベントは、 NSTableViewのデータを変更します。
これが私のコードです:
私のmainWindow.mファイルで
- (IBAction)btn1Event:(id)sender {
if (!detailwindow) {
detailwindow = [[DetailWindow alloc] initWithWindowNibName:@"DetailWindow"];
detailwindow.mainwindow = self;
}
detailwindow.title = @"First";
[detailwindow showWindow:self];
}
- (IBAction)btn2Event:(id)sender{
if (!detailwindow) {
detailwindow = [[DetailWindow alloc] initWithWindowNibName:@"DetailWindow"];
detailwindow.mainwindow = self;
}
detailwindow.title = @"Second";
[detailwindow showWindow:self];
}
詳細ウィンドウで
- (void)windowDidLoad
{
[super windowDidLoad];
[tableView setBackgroundColor:[NSColor clearColor]];
[tableView setHeaderView:nil];
if([title isEqualToString:@"First"]){
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"MS.png"],@"image",@"first image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"CVS.png"],@"image",@"second image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"NS.png"],@"image",@"first image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"EM.png"],@"image",@"second image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"RES.png"],@"image",@"first image",@"text", nil]];
}
if ([title isEqualToString:@"Second"]) {
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"RS.png"],@"image",@"second image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"FB.png"],@"image",@"first image",@"text", nil]] ;
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"GT.png"],@"image",@"second image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"SKIN.png"],@"image",@"first image",@"text", nil]];
[arrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:@"GP.png"],@"image",@"second image",@"text", nil]];
}
[tableView reloadData];
}
- (IBAction)GoToMainWindow:(id)sender {
[mainwindow showWindow:self];
}
最初のボタンをクリックすると、このif([title isEqualToString:@"First"])
イベントが呼び出され、テーブルビューに最初の 5 つの画像が表示されます。
その後、2 番目のボタンをクリックすると、テーブルに次の 5 つの画像が表示されません。if ([title isEqualToString:@"Second"])
このイベントは呼び出されていないため、データは変更されていません。
最初にsecond
ボタンをクリックすると、同じことが起こりfirst event
ます。
理由はありますか?2番目のボタンのいずれかをクリックしても、ウィンドウが解放されていないと思います。