Basic concepts help. making IB connection to a specific instance
Basic concepts help. making IB connection to a specific instance
- Subject: Basic concepts help. making IB connection to a specific instance
- From: Denis Stanton <email@hidden>
- Date: Wed, 16 Apr 2003 12:46:57 +1200
I have identified a gap in my basic understanding of Cocoa/Interface
Builder and I wonder if someone could give me a pointer in the right
direction. Sorry it takes so many words to describe my lack ignorance.
I have build a program that produces reports from a database. Much of
the logic is taken up with defining each report - which data items will
be listed in columns, which rows will be selected etc. I want to save
the definitions and reuse then so I have an array of report definitions.
My program has a main class which I will call MyDataSource. This
includes an MSMutableArray of reports.
I have a class named Report that holds the instance variables that
define a report
As the program has developed I have build almost all of the logic into
the MyDataSource class. If I want to do something to a Report instance
I refer to it with something like [[reports objectAtIndex: myIndex]
title] or [[reports objectAtIndex: myIndex] setTitle: @"Customer
Names"]
It has dawned on me that this is not a very good use of Object
principles. I should have put some these methods inside the Report
class.
I started off to do this, copying methods from MyDataSource to Report,
changing occurrences of [reports objectAtIndex: myIndex] to "self",
but I ran into a hole.
What do I do about the connections between these variables in a report
and the IBOutlets and IBActions?
For example, in MyDataSource.h I have
{
IBOutlet id reportTitle;
}
- (IBAction)takeReportTitleFrom: (id)sender;
and in MyDataSource.m
- (void)setUpSelectedReport{
[reportTitle setStringValue: [[reports objectAtIndex: reportIndex]
title]];
}
- (IBAction)takeReportTitleFrom: (id)sender{
[[reports objectAtIndex: reportIndex] setTitle: [sender
objectValue]];
}
I can move these methods to Reports.m and get rid of the [reports
objectAtIndex: reportIndex] code, but the problem for me comes in
Interface Builder. In order to be able to connect the reportTitle
IBOutlet to a text field in in my window, and to connect a button to
the takeReportTitleFrom: IBAction I need to instantiate the Report
class in IB so that a nice blue cube appears in the Instances panel of
my MainMenu.nib and I can wire the outlets and actions to the interface.
But that's obviously wrong because the instance of Report that I
instantiate in IB has no connection with the instances of Report that
live in the NSMutableArray in MyDataSource
I must have missed something basic here. I can't see how IB can have
an instance of any class except the main one. I suppose what I want is
to be able to select a report in MyDataSource and have it map the the
instance of Report that has been wired up in Interface Builder.
Can anyone give me a nudge (or maybe a whack on the side of the head)
at this point and tell me what fundamental concept of Cocoa-Interface
Builder I have missed?. Even if you can't, thank you for your time in
reading this far.
Denis Stanton
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.