• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSOutlineView selectedRow error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOutlineView selectedRow error?


  • Subject: Re: NSOutlineView selectedRow error?
  • From: Scott Harper <email@hidden>
  • Date: Tue, 7 Mar 2006 21:54:24 -0700

Thanks for the quick response. I've looked over my code, and I cannot seem to find the mistake. I use a custom data source, whose methods are as follows (hopefully this won't be too long...):

(NOTE: I have MQNode, which is a generic node as used in most any tree data structure (including basic calls for adding shildren, and requesting the number of children), and I have MQTemplate, which is a child of MQNode, but is really just supposed to be a leaf only. I load these all into a data structure from and XML file when the program loads, as well as loading the associated image files into the MQTemplate objects. The NSOutlineView has two columns, Image and Description. Image is set in Interface Builder as an NSImageCell. Description is whatever the default is. There's also the obligatory first column of arrows if the item is expandable.)

- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
if([[item className] isEqualToString:@"MQNode"])
return [item childCount];
else if(item == nil)
return [_root childCount];
else return 0;
}


- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id) item {
if([[item className] isEqualToString:@"MQNode"])
return YES;//[item childCount] > 0 ? YES : NO;
else return NO;
}


- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
if([[item className] isEqualToString:@"MQNode"])
return [item childAtLocalIndex:index];
else return [_root childAtLocalIndex:index];
}


- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn
byItem:(id)item {
if([[tableColumn identifier] isEqualToString:@"Description"])
return [item itemName];
else if([[item className] isEqualToString:@"MQNode"]) //this check must come first... >.<
return nil;//@"+";
else if([[item className] isEqualToString:@"MQTemplate"]) {
//NSLog(@"Asked for Image: %@", [item thumbnail]);
return [item image];
}
else return @"Bad item asked for!!";
}


- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn
item:(id)item {
if([[tableColumn identifier] isEqualToString:@"Description"])
return YES;
else return NO;
}


- (void)outlineView:(NSOutlineView *)olv setObjectValue:(id)object
		 forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  {
	[(MQNode *)item setItemName: object];

	//Reorder
	//[_root reorder];

	[[controller templateView] reloadData];
}

You see the (commented out here) call to [_root reorder], which simply uses the "sortUsingSelector:@selector(...)" method from NSMutableArray, then tells all child nodes to sort.

When I click the button I placed to draw the template image into my custom panel, here is the code I use to retrieve the image:

int selectedRow = [templateView selectedRow];

NSImage *ti = [[[templateView tableColumnWithIdentifier:@"Image"]
							dataCellForRow:selectedRow] objectValue];
NSLog(@"I think the currently selected row is: %x", selectedRow);
NSLog(@"Image test from Template: %@", ti);

This always prints out the appropriate number for the row I have selected. However, when I go through and DRAW the image, which I retrieved each time, the inconsistency arises as follows:

1) Click on a row, then click on ANY row above it, then click the button to draw the template. The image drawn is the PREVIOUSLY selected template, regardless of how many items above you selected. If you rise more, you get the second clicked row's image drawn. (Clicking a row and selecting any row BELOW it works as expected, however.)

2) Click on a row, the WITHOUT clicking another row, move the scroll bar up or down any significant amount. DO NOT select another row. When you click the button to draw the image, there will be a different image (selected from the CURRENTLY VISIBLE rows) drawn. This one seems to select either from the TOP or BOTTOM of the visible rows.

Keep in mind, the INTEGER returned by [templateView selectedRows] is always the same, but the image retrieved by [[[templateView tableWithColumnIdentifier:@"Image"] dataCellForRow:selectedRow] objectValue]; is not consistent at all across the two examples above.

Is this a bug in MY code or in APPLE's code?!? If mine (likely), can anyone please help me know where it may be? What I'm oing wrong? I've tried to follow the documentation as best as possible, but it's somewhat disjointed. >.<

--Scott


On Mar 4, 2006, at 6:27 PM, Greg Herlihy wrote:


NSOutlineView inherits from NSTableView, so many useful routines for an
outline table will be found in NSTableView.h, including those that select
rows and columns. So calling selectedRow is not a problem.


How is the data for the table supplied? Through bindings or a outline table
data source? If bindings are used, be sure to bind the outline table's
selectionIndexPaths to the selectionIndexPaths in the NSTreeController. And
if you are using a data source, it sounds like you may have an off- by-one
error.


Greg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Thumbnails
      • From: Valerio Ferrucci <email@hidden>
    • Re: NSOutlineView selectedRow error?
      • From: Corbin Dunn <email@hidden>
References: 
 >Re: NSOutlineView selectedRow error? (From: Greg Herlihy <email@hidden>)

  • Prev by Date: Default attributes when creating NSAttributedString from HTML?
  • Next by Date: Re: NSOutlineView selectedRow error?
  • Previous by thread: Re: NSOutlineView selectedRow error?
  • Next by thread: Re: NSOutlineView selectedRow error?
  • Index(es):
    • Date
    • Thread