views:

99

answers:

2

I have some code to do this (which is below) but I get one error stopping it from working and the error is ''MyOutlineView' may not respond to '-objectArray'', it says that it needs to be declared but I don't know what code I should use in the Header File to declare it.

The Code:

- (void) outlineView: (NSOutlineView *) aView
willDisplayCell: (id) aCell
forTableColumn: (NSTableColumn *)aColumn
item: (id) anItem
{
id rootObj = anItem;
unsigned row = [aView rowForItem:anItem];

[aCell setDrawsBackground: YES];

while ([aView levelForRow:row] != 0) {
row --;
rootObj = [aView itemAtRow:row];
}

// The colours here are foul and ugly. Use something else, for
// God's sake!
if ([[self objectArray] indexOfObject:rootObj] % 2)
[aCell setBackgroundColor: [NSColor yellowColor]];
else
[aCell setBackgroundColor: [NSColor blueColor]];
}
+1  A: 

Is objectArray an instance variable of MyOutlineView? If so, just access it directly, like this:

if( [objectArray indexOfObject:rootObj] % 2 )
...

The code [self objectArray] is trying to call a method called objectArray, not reference the ivar objectArray.

Edit: The above assumes that objectArray is an instance variable of MyOutlineView, like:

@interface MyOutlineView {
    NSArray* objectArray;
}
zpasternack
Once I do that it says that objectArray is un-declared, how would I declare it?
Joshua
It should be declared in MyOutlineView's @interface section, see my edit above.
zpasternack
That get rid of the Error, Thanks! But for some reason the code is not doing what it should do to my Outline View. Do you know why this is?
Joshua
@Joshua. Now that you've declared objectArray, are you initialising it correctly?
Abizern
I've set the class of the Outline View to MyOutlineView, so it should work. Can you see any errors in the code and are you sure your code does the exact same code as it replaces?
Joshua
Also if objectArray was not an instance variable of MyOutlineView, what would I need to change or do to get rid of the error?
Joshua
Why do you think it is happening?
Joshua
It isn't enough to just declare the objectArray as an array. You have to put something in it.
Abizern
I have an array and a Tree controller, which is being used with with Core Data, do I need to use an IBOutlet to connect the Outlet - objectArray - to the Array/Tree Controller I am using for core data?
Joshua
I have an array which is being used with core data, but how do I tell it to use that Array?
Joshua
+3  A: 

I'm not sure that I am 100% sure of what you are trying to do here, but it does seem to me that you could simply replace this:

  if ([[self objectArray] indexOfObject:rootObj] % 2)
    [aCell setBackgroundColor: [NSColor yellowColor]];
  else
    [aCell setBackgroundColor: [NSColor blueColor]];

with

if ([aView rowForItem:rootObj] % 2) 
  [aCell setBackgroundColor: [NSColor yellowColor]];
else
  [aCell setBackgroundColor: [NSColor blueColor]];

Your rootObj is an item in the outline just as anItem is and this should tell you what row that root item is in. Of course, maybe I don't understand what you're trying to find there.

littleknown
That code works, but it stops my outline view from working. Any idea why?
Joshua
Do you know why this is happening?
Joshua
Afraid you'll have to be a little more precise, how does this stop your outline from working? Does it no longer display any data in rows, or columns or what.Did you have an objectArray method before that holds the contents of your data? where does that data come from?
littleknown
The Data comes from Core Data, the Outline Views rows data are displayed but the Background does not change. Any Ideas?
Joshua