• 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
NSTableView and displaying c strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView and displaying c strings


  • Subject: NSTableView and displaying c strings
  • From: Chinh Nguyen <email@hidden>
  • Date: Fri, 30 Nov 2007 17:23:25 -0600

I'm a Cocoa newbie trying to port my Carbon app to Cocoa for 64-bit GUI support so forgive my ignorance.

I've got data in memory and I want to display the variable names of the data (as well as other properties) which are stored as c strings (in the data) in an NSTableView. The data is operated on by code common to all the platforms we support (Mac, Windows, Unix) so I can't change the format of it. Maintaining the properties of my data in an array of NSStrings is not practical because the properties can change at any moment (there can be up to 32,000 variables) and I'm only notified that it has changed, not what has changed. It's also wasteful since the values are already there, just in the wrong format.

What I did for my tableView:objectValueForTableColumn:row: method is convert the c string for a given column and row to an NSString and return it (my simplified example assumes just one column).

- (id) tableView:(NSTableView *) tableView
	objectValueForTableColumn:(NSTableColumn *) tableColumn
	row:(int) row
{
	NSString	*string;

// VarName() is a wrapper for returning the pointer to a null- terminated c string given an index
string = [[NSString alloc] initWithCString:VarName(row)
encoding:NSMacOSRomanStringEncoding];
return(string);
}


I assume I have to release the NSStrings but I don't have any references to them so I subclassed NSTextFieldCell with my own drawWithFrame which draws the cell then releases the strings.

- (void) drawWithFrame:(NSRect) cellFrame inView:(NSView *) controlView
{
	[super drawWithFrame:cellFrame inView:controlView];
	[[self objectValue] release];
}

My question is is this a safe and or a correct thing to do?

The only other thing I can think of is to use an array of row indices (NSNumber) as my data source and write custom NSFormatters for each column of my NSTableView that can convert the indices to the strings I need.

Also, I need click-through support on my NSTableView so I subclassed it and return YES from acceptsFirstMouse. This doesn't have any effect. What do I need to do to get click-through support?

Also2, I've seen rendering problems in my NSTableView (stray horizontal scrollbar and header corner lines not erased) when it's resized (it resizes with its parent window). I even see it when using IB to test out an NSTableView. Is this a known issue?

-Chinh Nguyen
 email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTableView and displaying c strings
      • From: David Duncan <email@hidden>
  • Prev by Date: Of modal windows and nil-targeted menu actions
  • Next by Date: Re: NSTableView and displaying c strings
  • Previous by thread: Of modal windows and nil-targeted menu actions
  • Next by thread: Re: NSTableView and displaying c strings
  • Index(es):
    • Date
    • Thread