在过去的几个小时里,我一直在尝试解决这个问题,其中涉及大量搜索和观看视频。这是我正在尝试做的事情:
摘要:一个简单的窗口,允许我将邮件从我的收件箱移动到我的许多邮件文件夹中的任何一个。当我输入我正在寻找的邮件文件夹的名称时,大纲视图应该会自动刷新,只显示具有匹配文本的那些——如果你知道的话,想想 MsgFiler。
- 在文本框中键入文本
- 当我键入每个字母时,我希望 NSOutlineView 更新它的数据,以使与我的输入文本匹配的文件夹越来越少。(目前,我的测试只是在 NSOutlineView 中添加了一个“测试邮箱”
当前结果:
- 在文本框中键入文本
- 什么都没发生
- 单击 NSOutlineView,视图得到更新
文本域委托.m:
#import "TextFieldDelegate.h"
#import "OutlineViewController.h"
#import "GetMailDatasource.h"
@implementation TextFieldDelegate
@synthesize testLabel;
- (void) controlTextDidChange :(NSNotification *) sender {
NSTextField *changedField = [sender object];
NSLog(@"in control text did change");
//Just some text code to see the change when text does change
NSString *text = [changedField stringValue];
[testLabel setStringValue:text];
NSLog(@"changed the label and creating the data now");
OutlineViewController *vc = [[OutlineViewController alloc] init];
[vc refreshTheData:sender];
[vc.outlineView reloadData];
[vc release];
}
- (void)controlTextDidEndEditing:(NSNotification *)obj {
NSLog(@"in end editting");
return;
}
@end
大纲视图控制器.m
#import "OutlineViewController.h"
#import "GetMailDatasource.h"
@implementation OutlineViewController
- (id) init {
self = [super init];
if (self) {
_mailboxes = [[NSMutableArray alloc] init];
if (myMailboxes != nil) {
_mailboxes = myMailboxes;
} else {
GetMailDatasource *mailDatasource = [[GetMailDatasource alloc] init];
[mailDatasource createFakeData];
_mailboxes = myMailboxes;
}
}
NSLog(@"inited outline view controller");
return self;
}
- (IBAction) refreshTheData : (id) sender {
NSLog(@"in refreshTheData");
Mailbox *m = [self.outlineView itemAtRow:[self.outlineView selectedRow]];
if (m)
[m addChild:[[Mailbox alloc] init]];
else
[self.mailboxes addObject:[[Mailbox alloc] init]];
NSLog(@"running reloadData");
[self.outlineView reloadData];
}
#I know these work, but providing them for completeness
#pragma mark NSOutlineView Data Source Methods
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
return !item ? [self.mailboxes count] : [[ item children] count ];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return !item ? YES : [[item children ] count] != 0;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
return !item ? [self.mailboxes objectAtIndex:index] : [[item children] objectAtIndex:index];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return [item name];
}
@end
我确实有一个单独的“测试按钮”,我在界面上添加了它只是为了尝试,我已经将它的“发送操作”直接绑定到 OutlineViewController 上的“刷新数据”函数,并且可以顺利运行。在 NSOutlineView 中添加新项目并立即更新。
我不确定要找出问题所在还需要什么...任何建议将不胜感激!
非常感谢!