我正在创建一个Mac应用程序,其中有一些按钮的主窗口。切换到另一个窗口时窗口不会释放
当我点击按钮,它将打开一个带有NSTableview的DetailWindow
。每个buttonclickevent更改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];
}
在DetailWindow
- (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"])
事件电话,我可以在我的桌面视图中看到前五个图像。
之后,如果我点击第二个按钮,我看不到表中的下五个图像。数据没有变化,因为if ([title isEqualToString:@"Second"])
这个事件没有被调用。
如果我第一次点击second
按钮,那么first event
也会发生同样的情况。
任何想法为什么?其次,当我点击任何一个按钮时,我认为窗口不会释放。
首先非常感谢你的业余程序员。我试过这段代码。这次当我点击按钮时,两个事件都在调用,但**图像在表格**中没有改变。他们保持不变。我想我必须调用'[detailwindow showWindow:self];'如果我想单击事件的detailWindow ..我是ryt? – iUser
哦。你想“改变”它而不是添加数据吗?然后使用removeObjectsAtArrangedObjectIndexes删除arrayController中的所有数据:删除对象,然后添加对象,数据应该更改。 – TheAmateurProgrammer
好吧,我注意到一件事..如果我点击第一个按钮,然后第二个按钮它添加它的所有5图像下方的现有图像(第一个按钮的图像)。所以我得到所有10个图像在第二次点击..任何帮助? – iUser