 |
 |
More NSTableView fun
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status:
Offline
|
|
Still fighting my evil NSTableView. Almost conquered it, but one last nagging problem: my data source isnt found.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (int)numberOfRowsInTableView  NSTableView *)aTableView
{
if (aTableView == dateList) {
return [[workouts dates] count];
}
else if (aTableView == exerciseList) {
return [[workouts exercises] count];
} else {
NSLog(@"No Data Source"  ;
return nil;
}
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I get a crapload of No Data Source messages. I set the data source in my awakeFromNib method for my controller as well as defined an instance of my FTExerciseList class which houses the dates & exercises mutable arrays that hold the data.
Anyone offer some suggestions? I am at a loss after an evening of this.
<small>[ 07-16-2002, 01:27 AM: Message edited by: Justin W. Williams ]</small>
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Justin W. Williams:
<strong>Still fighting my evil NSTableView. Almost conquered it, but one last nagging problem: my data source isnt found.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (int)numberOfRowsInTableView  NSTableView *)aTableView
{
if (aTableView == dateList) {
return [[workouts dates] count];
}
else if (aTableView == exerciseList) {
return [[workouts exercises] count];
} else {
NSLog(@"No Data Source"  ;
return nil;
}
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I get a crapload of No Data Source messages. I set the data source in my awakeFromNib method for my controller as well as defined an instance of my FTExerciseList class which houses the dates & exercises mutable arrays that hold the data.
Anyone offer some suggestions? I am at a loss after an evening of this.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">To compare two objects, you must use -[NSObject isEqual:], so change your code to:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (int)numberOfRowsInTableView  NSTableView *)aTableView
{
if ([aTableView isEqual:dateList]) {
return [[workouts dates] count];
}
else if ([aTableView isEqual:exerciseList]) {
return [[workouts exercises] count];
} else {
NSLog(@"No Data Source"  ;
return nil;
}
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Justin W. Williams:
<strong>Still fighting my evil NSTableView. Almost conquered it, but one last nagging problem: my data source isnt found.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (int)numberOfRowsInTableView  NSTableView *)aTableView
{
if (aTableView == dateList) {
return [[workouts dates] count];
}
else if (aTableView == exerciseList) {
return [[workouts exercises] count];
} else {
NSLog(@"No Data Source"  ;
return nil;
}
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I get a crapload of No Data Source messages. I set the data source in my awakeFromNib method for my controller as well as defined an instance of my FTExerciseList class which houses the dates & exercises mutable arrays that hold the data.
Anyone offer some suggestions? I am at a loss after an evening of this.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">This probably means that dateList and exerciseList aren't properly pointing at the table views you want them to. Look at your code--the "No Data Source" message means that aTableView isn't either of the table views you're looking for. Try doing a check on exerciseList and dateList to see what the heck they are.
EDIT: By the way, just so you know, it's not technically right to return nil here. nil is an id, while this method purports to return an int. It shouldn't be a huge problem, since I think it will get typecast to (int)0 anyway, but it's good practice to make sure your return types match.
<small>[ 07-16-2002, 10:23 AM: Message edited by: Chuckit ]</small>
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status:
Offline
|
|
Revised code to use isEqual: rather than == in the if structures.
Did a po of dateList & exerciseList and received nil values.
In FTController.m, I have set the data source like so:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (void)awakeFromNib
{
[self setupToolbar];
workouts = [[FTExerciseList alloc] init];
[dateList setDataSource:[workouts dates]];
[exerciseList setDataSource:[workouts exercises]];
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Also have outlets created in IB + data sources set for both tables.
Are my setDataSource: methods illegal?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Justin W. Williams:
<strong>...
Are my setDataSource: methods illegal?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">short answer: depends
long answer: what kind of object do [workouts dates] and [workouts exercises] return?
do those objects implement the required delegate methods? if they're ordinary nsarrays, the answer is: they don't implement them, that's not going to work. if you use an own object that implements them or a category in which you extended nsarray, the answer is: fine.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Justin W. Williams:
<strong>Revised code to use isEqual: rather than == in the if structures.
Did a po of dateList & exerciseList and received nil values.
In FTController.m, I have set the data source like so:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">- (void)awakeFromNib
{
[self setupToolbar];
workouts = [[FTExerciseList alloc] init];
[dateList setDataSource:[workouts dates]];
[exerciseList setDataSource:[workouts exercises]];
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Also have outlets created in IB + data sources set for both tables.
Are my setDataSource: methods illegal?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Well, if dateList and exerciseList are indeed nil, then setting their data sources is pretty pointless, right? First make sure those outlets are connected to the appropriate NSTableViews (I assume they're NSTableViews). Getting those to equal the table views you want should be your top priority, because you're not going to get nil to do anything for you.
In anticipation of a possible future problem, though, are you sure that you meant to give the two NSTableViews different data sources? In the code you posted earlier, it looked like they shared a data source.
And by the way, I think you'll find that the == route was correct. You don't want to compare two objects; you just want to see if both variables represent the same object, right? Ibson was right about using -isEqual: for comparing two objects, but if you're actually just checking to make sure it's not two objects, I think == is appropriate.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">long answer: what kind of object do [workouts dates] and [workouts exercises] return?
do those objects implement the required delegate methods? if they're ordinary nsarrays, the answer is: they don't implement them, that's not going to work. if you use an own object that implements them or a category in which you extended nsarray, the answer is: fine.
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">the FTExerciseList class has NSMUtableArray workouts & NSMutableArray dates.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Chuckit:
<strong>Well, if dateList and exerciseList are indeed nil, then setting their data sources is pretty pointless, right? First make sure those outlets are connected to the appropriate NSTableViews (I assume they're NSTableViews). Getting those to equal the table views you want should be your top priority, because you're not going to get nil to do anything for you.
In anticipation of a possible future problem, though, are you sure that you meant to give the two NSTableViews different data sources? In the code you posted earlier, it looked like they shared a data source.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">They do share the same datasource. Each table points to a different array in the datasource, however.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Justin W. Williams:
<strong>the FTExerciseList class has NSMUtableArray workouts & NSMutableArray dates.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">are they "standard" nsmutablearrays or do you define a category?
or in other words: do these arrays implement the required datasource methods in order to be a valid datasource?
remember, it *does* matter where you implement your datasource methods. if you implement them in your controller or the table's delegate, that doesn't mean you *datasource* (the arrays, as we just found out) implements them.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
The data source methods, such as:
- (int)numberOfRowsInTableView  NSTableView *)aTableView
Must be implemented within the class implementation of the class of the object you set as the datasource.
Eg, if you set the datasource like this:
[dateList setDataSource:blah];
then the data source methods must be defined withing the class implementation of whatever class the object "blah" belongs to.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Justin W. Williams:
<strong>They do share the same datasource. Each table points to a different array in the datasource, however.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">But if the array isn't the data source, you wouldn't use the array in the -setDataSource: call. The NSTableView doesn't care where the data actually comes from--it just needs to know what object will respond to its requests for data.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
OK, there is some confustion happening here, so I recommend starting with the basics... (later on you can deal with categories, etc)
• First, don't bother with the [aTableView isEqual:...], your original comparison statement is fine, that is
if (aTableView == dateList)
is valid since you want to be comparing 2 addresses, not the contents of the objects.
• Second, because your outlets dateList and exerciseList are nil, this probably means that you haven't connected these ourlets to the NSTableViews in Interface Builder
• Third, set the datasouce from InterfaceBuilder if you can to be your controller class. You won't need to set it in awakeFromNib, but if you do choose to set it there, it needs to be set to the controller object, e.g.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> [dateList setDataSource:self];
[exerciseList setDataSource:self];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">(This example assumes that the object making these calls are indeed your datasource, which is the simple example)
• Fourth, don't think of the NSTableView's datasource as the array with the data. The datasource is an object that will handle (at a minimum)
i) the number of rows to be listed (via the
- (int) numberOfRowsInTableView:
method)
ii) the value of the cell being displayed (via the
- (id) tableView: objectValueForTableColumn: row:
method)
Your single datasource can return a different numberOfRows and different cell values for different tableViews
• Fifth, the datasource methods described above then return values from your array. Assuming your NSTableView outlets are dateList and exerciseList, your numberOfRowsInTableView method should be
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> if (aTableView ==dateList) {
return [[workouts dates] count];
}
else if (aTableView ==exerciseList) {
return [[workouts exercises] count];
} else {
NSLog(@"TableView not found"  ;
return 0;
} </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">As an exercise for you, you will need to return values for
- (id) tableView: objectValueForTableColumn: row:
method)
based on the values of your [workouts dates] and [workouts exercises] arrays
Hope this clears some confusion...
<small>[ 07-18-2002, 02:59 PM: Message edited by: Brad Brack ]</small>
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Brad Brack:
<strong>
Third, set the datasouce from InterfaceBuilder if you can to be your controller class. You won't need to set it in awakeFromNib, but if you do choose to set it there, it needs to be set to the controller object, e.g.
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> [dateList setDataSource:self];
[exerciseList setDataSource:self];</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">(This example assumes that the object making these calls are indeed your datasource, which is the simple example)
</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">So I should move all my tableView methods (ie. objectValueForTableColumn, etc) to my Controller, rather than my FTExerciseList class (which houses the two arrays that I wish to pull the data from)?
Seems like I have gotten in over my head a wee bit...
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2000
Location: Los Altos, CA, USA
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">So I should move all my tableView methods (ie. objectValueForTableColumn, etc) to my Controller, rather than my FTExerciseList class (which houses the two arrays that I wish to pull the data from)?
</font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">In the simplest case, you can use a single controller. This will help you come to understand the "Model-View-Controller" concept. In most cases, a single controller is sufficient, and a lot easier to deal with. I have a feeling that it will save you a lot of headache and that you don't really need a separate controller.
In that Colored Row Table View example that I posted a while ago, I created separate controllers for each of the 2 table views mostly for the sake of clarity. In practice, I have multiple table views in a nib which all use the same file's owner controller. The arrays are instance variables in the file's owner's class.
Don't get me wrong- there are times when it is a better idea (and sometimes required) to have separate controllers (and separate data sources) - however if it isn't compelling, and you aren't quite sure of the concepts, it will become a bear.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2001
Location: Evansville, IN
Status:
Offline
|
|
Problem resolved.
I reworked my whole program to a much more managable way thanks to everyone's help here.
Thanks to all for the help!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|