Reputation: 6656
I'm a beginner in objective-c and want to realize a simple GUI: A MyMainWindowController
with a corresponding xib wich contains a table and a simple Add
button.
@interface MyMainWindowController : NSWindowController
{
}
@end
The implementation code of the controller is nearly empty (pre-defined initWithWindow and windowDidLoad). The AddressTvc
is defined like this:
@interface AddressTvc : NSObject <NSTableViewDataSource>
{
@private
IBOutlet NSTableView *myTableView;
NSMutableArray *list;
}
- (IBAction)add:(id)sender;
@end
This works fine. I can click on the Add
button and a new row is inserted in the table.
It seems that the AddressTvc
is created automatically (by the IB?) when the MyMainWindowController
is visible. I want a reference in the code of MyMainWindowController
to AddressTvc
so I'm able to fill the table with some data retrieved by a background thread. This should be done by calling the - (IBAction)add:(id)sender;
method.
I tried to create a AddressTvc
inside the MyMainWindowController
but then the object is initialized twice. I'm sure I have to wire it somewhere in the IB, but have no clue where to do this ...
Upvotes: 0
Views: 143
Reputation: 13177
Create an outlet in you MyMainWindowController class that can point to your table view controller class.
E.G.
@interface MyMainWindowController : NSWindowController
{
IBOutlet AddressTvc *myTVC
}
@end
Then simply control+drag from your file owner to the instance of the table view controller in interface builder and you can now access it in your window controllers code.
Upvotes: 1