NSTableView 和 NSMutableArray 之间的 Cocoa 绑定拒绝更新
好吧,我对 Obj-C 和 Cocoa 很陌生,但我确信我在这里的绑定是正确的。我一直在谷歌搜索,搜索堆栈溢出,并一次又一次地检查我的值。
所以,这是我的绑定:
它们连接到此类:
@interface TMMaddMangaWindowDelegate : NSWindowController {
...
}
...
@property (copy) NSMutableArray* mangaList;
...
@end
@implementation TMMaddMangaWindowDelegate
...
@synthesize mangaList;
// - (NSMutableArray*) mangaList {
// NSLog(@"mangaList was called!");
// return mangaList;
//}
//- (void) setMangaList:(NSMutableArray *) input{
// NSLog(@"setMangaList was called!");
// [mangaList autorelease];
// mangaList = [input retain];
//}
...
-(void) populateList:(NSArray*)list{
NSMutableArray* newArray = [[NSMutableArray alloc] initWithArray:list];
NSLog(@"Populating List.");
for(NSXMLNode* node in list){
[newArray addObject:node.description];
//[[self mutableArrayValueForKey:@"mangaList"] addObject:node.description];
//NSLog(@"%@", node.description);
}
[self setMangaList:newArray];
[[self chapterListDownloadIndicator] stopAnimation:self];
}
如您所见,我还尝试了 mutableArrayValueForKey
方法,但一无所获。我知道事实上 mangaList 正在获得物品。
我已经为此工作了一段时间,并且可能犯了一个愚蠢的错误。
提前致谢。
Ok, I'm very new to Obj-C and Cocoa, but I'm sure my bindings here are correct. I've been googling, searching stack overflow and have checked my values again and again.
So, here are my bindings:
They connect to this class:
@interface TMMaddMangaWindowDelegate : NSWindowController {
...
}
...
@property (copy) NSMutableArray* mangaList;
...
@end
@implementation TMMaddMangaWindowDelegate
...
@synthesize mangaList;
// - (NSMutableArray*) mangaList {
// NSLog(@"mangaList was called!");
// return mangaList;
//}
//- (void) setMangaList:(NSMutableArray *) input{
// NSLog(@"setMangaList was called!");
// [mangaList autorelease];
// mangaList = [input retain];
//}
...
-(void) populateList:(NSArray*)list{
NSMutableArray* newArray = [[NSMutableArray alloc] initWithArray:list];
NSLog(@"Populating List.");
for(NSXMLNode* node in list){
[newArray addObject:node.description];
//[[self mutableArrayValueForKey:@"mangaList"] addObject:node.description];
//NSLog(@"%@", node.description);
}
[self setMangaList:newArray];
[[self chapterListDownloadIndicator] stopAnimation:self];
}
As you can see, I also tried the mutableArrayValueForKey
approach, which yielded nothing. I know for a fact mangaList is gaining items.
I've been working on this for a while, and probably made a stupid mistake.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在数组控制器背后更改
mangaList
。每当您对mangaList
进行更改时,您应该首先调用[self willChangeValueForKey:@"mangaList"];
,然后调用[self didChangeValueForKey:@"mangaList"] ;
完成更改后。这将使阵列控制器知道它需要查看发生了什么变化。It looks like you are changing
mangaList
behind the array controller's back. Whenever you are making a change tomangaList
you should first call[self willChangeValueForKey:@"mangaList"];
and then[self didChangeValueForKey:@"mangaList"];
once you are done with the change. this will let the array controller know it needs to take a look at what changed.事实证明,问题在于窗口没有将文件所有者的类标识设置为我的窗口控制器/委托。当我设置它的那一刻,窗口就活了。
这个问题也导致我的 NSProgressIndicator 无法工作。
It turns out that the problem was that the window did not have the class identity of Files Owner set to my window controller/delegate. The moment I set this the window sprang to life.
That problem was also preventing my NSProgressIndicator from working.