开发者

How to access methods/variables from swapped custom view

开发者 https://www.devze.com 2023-03-14 23:42 出处:网络
I\'ve created a window that contains an NSSplitView in which case the right custom view 开发者_高级运维has a view that I swap into at runtime. The custom view swapped in contains a NSTableView with da

I've created a window that contains an NSSplitView in which case the right custom view 开发者_高级运维has a view that I swap into at runtime. The custom view swapped in contains a NSTableView with data inside it. I have a search box in the main window of the application that I want to be able to constrain the rows of the table view with.

I have the code to do this and I know it works, but the code I have was tested with a search text box and table view that were on the same window scope. With the text search box now being in the main window and the table view being in a different custom view, I'm not sure how to get the text search box to call the relevant methods from the custom view's controller class, because I don't have direct access to these method anymore.

I'm sure this is a very beginner question, but any help would be appreciated. Thanks.


Have your main window controller pass the search query or filter predicate to a property of the content view controller.

You can give the main window controller a weak-referencing (assign) property that holds the current content view controller. Implement a custom setter that not only assigns to the backing instance variable, but also does the swap. That, any time it's time to do a swap, you simply say self.currentContentViewController = viewControllerToSwapIn, and when it's time to change the query/predicate, you pass it to self.currentContentViewController.searchQuery (having implemented the searchQuery property in the MainContentViewController class and made all your actual content-view controllers inherit from that class).

0

精彩评论

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