开发者

Cocoa Core Data and Tab View - How do I tell when Tab View is finished "loading" so I can tell the view to initialize itself?

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 th开发者_开发技巧us 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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜