在 NSTableView 中显示 NSArray 中的数据

发布于 2024-08-13 07:15:10 字数 1013 浏览 11 评论 0原文

我有一个问题,我认为有一个非常简单的解决方案,但我无法理解它!

我有这段代码:

NSManagedObjectContext * context  = [[NSApp delegate] managedObjectContext];
    NSManagedObjectModel   * model    = [[NSApp delegate] managedObjectModel];
    NSDictionary           * entities = [model entitiesByName];
    NSEntityDescription    * entity   = [entities valueForKey:@"Post"];

    NSPredicate * predicate;
    predicate = [NSPredicate predicateWithFormat:@"date < %@", [NSDate date]];

    NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
    NSArray * sortDescriptors = [NSArray arrayWithObject: sort];

    NSFetchRequest * fetch = [[NSFetchRequest alloc] init];
    [fetch setEntity: entity];
    [fetch setPredicate: predicate];
    [fetch setSortDescriptors: sortDescriptors];

    NSArray * results = [context executeFetchRequest:fetch error:nil];
    [sort release];
    [fetch release];    

这会返回数组中的指定数据。我现在想在 NSTableView 中显示这些数据。

我该怎么做呢?

谢谢!

I have a problem, and I reckon there's a really straightforward solution to it, but I can't fathom it out!

I have this piece of code:

NSManagedObjectContext * context  = [[NSApp delegate] managedObjectContext];
    NSManagedObjectModel   * model    = [[NSApp delegate] managedObjectModel];
    NSDictionary           * entities = [model entitiesByName];
    NSEntityDescription    * entity   = [entities valueForKey:@"Post"];

    NSPredicate * predicate;
    predicate = [NSPredicate predicateWithFormat:@"date < %@", [NSDate date]];

    NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
    NSArray * sortDescriptors = [NSArray arrayWithObject: sort];

    NSFetchRequest * fetch = [[NSFetchRequest alloc] init];
    [fetch setEntity: entity];
    [fetch setPredicate: predicate];
    [fetch setSortDescriptors: sortDescriptors];

    NSArray * results = [context executeFetchRequest:fetch error:nil];
    [sort release];
    [fetch release];    

This returns the specified data in an Array. I now want to display this data in a NSTableView.

How would I go about doing this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡墨 2024-08-20 07:15:10

您可以将其用作绑定到 NSTableView 的 NSArrayController 的数据。

You could use it as the data for an NSArrayController which you bind to the NSTableView.

阳光①夏 2024-08-20 07:15:10

看来您需要阅读绑定。

Looks like you need to read into bindings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文