使用阵列控制器根据另一个弹出窗口中的选择来限制一个弹出窗口中的视图。不基于核心数据

发布于 2024-08-16 07:41:36 字数 785 浏览 11 评论 0原文

我正在开发一个不基于核心数据的应用程序 - 数据源是一系列网络服务。

根据数据源创建两个数组。第一个保存季节数据,每个数组对象都是一个 NSDictionary。其中两个 NSDictionary 条目保存要在弹出窗口中显示的数据(“seasonName”)和一个 id(“seasonID”),该 id(“seasonID”)充当为该季节定义的比赛的指针(在外部表中)。

第二个数组也是 NSDictionaries 的集合。其中两个条目保存要在弹出窗口中显示的数据(“matchDescription”)和指向第一个数组中 NSDictionaries 中定义的 seasonId 的 id(“matchSeasonId”)。

我有两个 NSPopUp。我希望第一个显示赛季名称,第二个显示为该赛季定义的比赛,具体取决于第一个中的选择。

我是装订新手,所以如果我错过了一些明显的东西,请原谅。 我尝试使用 ArrayControllers,如下所示:

SeasonsArrayController: 内容绑定到 appDelegate seasonsPopUpArrayData。

季节弹出窗口: 内容绑定到 SeasonsArrayController.arrangedObjects;内容值绑定到 SeasonsArrayController.arrangedObjects.seasonName

我看到季节名称很好。 显然,我可以按照类似的路线观看比赛,但随后我会看到所有比赛,而不是将列表限制为突出显示的赛季比赛。

我能找到的所有教程似乎都围绕核心数据并利用其中定义的关系。我这里没有那么奢侈。 非常感谢任何帮助。

I am working on an app that is not core data based - the data feed is a series of web services.

Two arrays are created from the data feed. The first holds season data, each array object being an NSDictionary. Two of the NSDictionary entries hold the data to be displayed in the popup ('seasonName') and an id ('seasonID') that acts as a pointer (in an external table) by matches defined for that season.

The second array is also a collection of NSDictionaries. Two of the entries hold the data to be displayed in the popup ('matchDescription') and the id ('matchSeasonId') that points to the seasonId defined in the NSDictionaries in first array.

I have two NSPopUps. I want the first to display the season names and the second to display the matches defined for that season, depending on the selection in the first.

I'm new at bindings, so excuse me if I've missed something obvious.
I've tried using ArrayControllers as follows:

SeasonsArrayController:
content bound to appDelegate seasonsPopUpArrayData.

seasonsPopup:
content bound to SeasonsArrayController.arrangedObjects; content value bound to SeasonsArrayController.arrangedObjects.seasonName

I see the season names fine.
I can obviously follow a similar route to see the matches, but I then see them all, instead of restricting the list to the matches for the season highlighted.

All the tutorials I can find seem to revolve around core data and utilise the relationships defined therein. I don't have that luxury here.
Any help very gratefully received.

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

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

发布评论

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

评论(1

辞别 2024-08-23 07:41:36

这不是一个答案——更多的是前一个问题的延伸。

我创建了 MatchesArrayController 并将其从 NSArrayController 子类化以允许进行一些自定义。

按照“Cocoa Bindings Topics”中“使用自定义数组控制器进行过滤”中的示例,我遵循了与上面相同的想法:
MatchessArrayController:绑定到 appDelegate matchesPopUpArrayData 的内容。

matchesPopup:绑定到MatchesArrayController.arrangedObjects的内容;内容值绑定到 MatchesArrayController.arrangedObjects.matchDescription。

我从 seasonPopUp:sender 派生了所选项目,并使用它来标识 seasonId。
这个想法是通过定义以下内容来更改 MatchesArrayController 中的排列对象:

- (NSArray *)arrangeObjects:(NSArray *)objects
{
    if (searchString == nil) {
        return [super arrangeObjects:objects];
    }

    NSMutableArray *filteredObjects = [NSMutableArray arrayWithCapacity:[objects count]];
    NSEnumerator *objectsEnumerator = [objects objectEnumerator];
    id item;

    while (item = [objectsEnumerator nextObject]) {
        if ([[[item valueForKeyPath:@"matchSeasonId"] stringValue] rangeOfString:searchString options:NSAnchoredSearch].location != NSNotFound) {
            [filteredObjects addObject:item];
        }
    }
    return [super arrangeObjects:filteredObjects];
}

- (void)searchWithString:(NSString *)theSearchString {
    [self setSearchString:theSearchString];
    [self rearrangeObjects];
}

- (void)setSearchString:(NSString *)aString
{
   [aString retain];
    [searchString release];
    searchString=aString;
}

我已经使用 NSLog 来检查事情是否按照预期的方式发生,并且一切似乎都正常。
然而,它仍然没有达到我想要的效果。

[自我重新排列对象];应该调用arrangeObjects方法,但没有。我必须明确地称呼它
(即[matchesArrayController arrayObjects:matchesPopUpArrayData];)

即使如此,尽管filteredObjects按预期方式更改,但下拉列表并未按我希望的方式更新。

This is not an answer - more an extension of the previous problem.

I created MatchesArrayController and subclassed it from NSArrayController to allow some customisation.

Following the example in 'Filtering Using a Custom Array Controller' from 'Cocoa Bindings Topics', I followed the same idea as above:
MatchessArrayController: content bound to appDelegate matchesPopUpArrayData.

matchesPopup: content bound to MatchesArrayController.arrangedObjects; content value bound to MatchesArrayController.arrangedObjects.matchDescription.

I've derived the selected item from seasonPopUp:sender and used this to identify the seasonId.
The idea is to change the arrangedObjects in MatchesArrayController by defining the following in;

- (NSArray *)arrangeObjects:(NSArray *)objects
{
    if (searchString == nil) {
        return [super arrangeObjects:objects];
    }

    NSMutableArray *filteredObjects = [NSMutableArray arrayWithCapacity:[objects count]];
    NSEnumerator *objectsEnumerator = [objects objectEnumerator];
    id item;

    while (item = [objectsEnumerator nextObject]) {
        if ([[[item valueForKeyPath:@"matchSeasonId"] stringValue] rangeOfString:searchString options:NSAnchoredSearch].location != NSNotFound) {
            [filteredObjects addObject:item];
        }
    }
    return [super arrangeObjects:filteredObjects];
}

- (void)searchWithString:(NSString *)theSearchString {
    [self setSearchString:theSearchString];
    [self rearrangeObjects];
}

- (void)setSearchString:(NSString *)aString
{
   [aString retain];
    [searchString release];
    searchString=aString;
}

I've used NSLog to check that things are happening the way they are supposed to and all seems ok.
However, it still doesn't do what I want.

[self rearrangeObjects]; is supposed to invoke the arrangeObjects method but doesn't. I have to call it explicity
(i.e.[matchesArrayController arrangeObjects:matchesPopUpArrayData]; )

Even then, although filteredObjects gets changed the way it is supposed to, the drop down list does not get updated the way I want it to.

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