Cocoa Core Data 和 Tab View - 如何判断 Tab View 何时完成“加载”所以我可以告诉视图自行初始化?
我正在构建一个简单的核心数据应用程序来尝试理解核心数据。它有两个实体:一个气象站和给定气象站的观测集合。
我为此创建了初始界面,方法是在窗口上放置一个选项卡视图,选择第一个选项卡,然后将气象站实体拖到该视图上;然后选择第二个选项卡并将观察实体拖动到第二个选项卡上。
然后,我自己创建了第三个选项卡,并在顶部添加了一个弹出窗口。此弹出窗口绑定到 StationArrayController,因此它会填充我添加的所有气象站。这很好用。
然后,我添加了一个表格视图来显示与所选站点关联的观测值。这也很有效。我使用一种方法实现了这一点,该方法创建一个谓词,搜索其站点与所选站点匹配的所有观测,并将谓词附加到与第三个选项卡上的表视图关联的 ObservationArrayController。 (我不知道如何在IB中做到这一点,所以我以编程方式完成了)。
错误是这样的:如果我加载以前保存的包含气象站和观测结果的文件,当我转到第三个选项卡时,即使选择了其中一个气象站(即,它出现在弹出窗口),所有观测值都出现在表格视图中,而不仅仅是与该站相关的观测值。
发生这种情况是因为我没有调用将谓词附加到观察数组控制器的方法,直到我实际使用弹出窗口手动更改站。
所以我的问题和问题是这样的(抱歉花了这么长时间才到达这一点!):我如何检测选项卡视图何时加载,以便我可以强制附加谓词的方法运行,从而获得初始列表与所选站点匹配的观测结果?
我尝试创建一个自定义 View 类,并将其子类化为第三个选项卡视图,并将此代码放入 awakeFromNib 方法中,但这在该过程中为时过早(此时“选定的站”在加载过程中为 -1)。
任何帮助将不胜感激。谢谢你!!
伊丽莎白
I have a simple Core Data app I am building to try to understand Core Data. It has two entities: a weather station, and a collection of observations for a given station.
I created the initial interface for this by putting a tab view on my window, selecting the first tab, and dragging the weather station entity onto that view; then selecting the second tab and dragging the observations entity onto the second tab.
I then created a third tab myself and added a popup at the top. This popup is bound to the StationArrayController, so it populates with all the weather stations I add. This works great.
I then added a table view to display the Observations associated with the selected Station. This also works great. I implemented this with a method that creates a predicate that searches for all observations whose station matches the selected station, and attached the predicate to the ObservationArrayController associated with the Table View on the third tab. (I couldn't figure out how to do this in IB, so I did it programmatically).
The bug is this: If I load a previously saved file with weather stations and observations in it, when I go to the third tab, even though one of the stations is selected (ie, it appears in the popup), all of the observations appear in the tableview, not just the ones associated with that station.
This is happening because I am not calling the method to attach the predicate to the Observation Array Controller until I actually use the popup to change the station manually.
So my problem and question is this (sorry it took so long to get to this point!): How can I detect when the tab view has loaded so I can force the method which attaches the predicate to run and thus have an initial list of Observations which matches the selected Station?
I tried creating a custom View class and subclassing it for the third tab view and putting this code in the awakeFromNib method, but this is too early in the process (the "selected station" is -1 at this point in the loading process).
Any help would be much appreciated. thank you!!
Elisabeth
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,我刚刚回答了我自己的问题!
我将 tabview 的委托设置为 MyDocument,并在那里实现 tabView:didSelectTabViewItem: 。我在 MyDocument 中创建了一个指向第三个选项卡视图的 IBOutlet,并在该方法中检查是否选择了第三个选项卡,如果是,则调用该方法将谓词附加到 ObservationArrayController。效果很好!
Ah, I just answered my own question!
I set the delegate of the tabview to MyDocument, and implemented tabView:didSelectTabViewItem: there. I created an IBOutlet in MyDocument pointing to the third tab view, and in this method, checked to see if the third tab was selected, and if so, called the method to attach the predicate to the ObservationArrayController. Works great!