0

I've got a user interface that looks pretty much like iTunes. For purposes of encapsulation, the top area and the main table view are in separate classes with separate nibs. I want to bind the search field from the top view controller to the tableview in the bottom view controller. I've arranged it so there are properties to store the NSArrayController in both classes. The array controller is an array of dictionaries, and the dictionaries have a "search_keywords" key that I want to use to filter the tableview.

Is it possible to set up the search stuff in Interface Builder even though it's in a separate nib? I can't figure out what to put in the various boxes.

If it's not possible with IB, I assume it's possible in code, since there is a view controller with references to both of the sub-view controllers and I can get at the search field, table view and array controller objects through properties on the two classes.

How do I set it up? IB would be best, if it's possible.

jsd
  • 7,673
  • 5
  • 27
  • 47

2 Answers2

0

What I did was use the NSSearchField in the top view controller as a dummy/placeholder. I create the "real" search field in the tableview's nib, and wire up all the bindings stuff as per normal. Then in the main view controller I grab the search field out of the tableview's nib, and replace the dummy searchfield with the real one using replaceSubview:with:

Now I can continue to use IB to modify the bindings, and it doesn't really matter what's in what nib as it all gets placed properly in the view hierarchy at runtime.

jsd
  • 7,673
  • 5
  • 27
  • 47
-1

In your concept you cannot bind the search field in IB in the desired way.

Do it like 1. Create an accessor-method (accessorMethodForTextInSearchField or what name you want to use) in the TopClass for the Text in the searchField 2. Import the TopClass.h in the MainClass 3. In MainClass you can use NSString *searchString = [ NSString stringWithString:[ TopClass accessorMethodForTextInSearchField] ]; 4. Now search for searchString in the array

macrene
  • 198
  • 1
  • 8
  • What if I put the NSSearchField in the same nib as the NSTableView, and then just copy it into the top view controller using the container view controller? – jsd Mar 08 '14 at 19:54
  • Then you have TWO DIFFERENT INDEPENDENT NSSearchFields. – macrene Mar 08 '14 at 20:01
  • No, I would move the search field from the tableview nib into the top view controller's view. (removeFromSuperview/addSubview) – jsd Mar 08 '14 at 22:07
  • I'm surprised, my code would have solved your problem, but you didn't try it and quote it negative. That's a special kind of treating somebody, who spends his time because he wanted to help you solving your problem. – macrene Mar 09 '14 at 00:41
  • Sorry you feel slighted - I do appreciate that you took the time to respond. However, you didn't solve the problem with Cocoa Bindings, which was the first two words of the question. – jsd Mar 09 '14 at 15:18