• 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: Getting started with NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting started with NSTableView


  • Subject: Re: Getting started with NSTableView
  • From: Andrew Merenbach <email@hidden>
  • Date: Fri, 7 Nov 2008 08:58:05 -0800


On Nov 7, 2008, at 8:37 AM, Benjamin Dobson wrote:

Hi all,

I'm trying to use an NSTableView for the first time. I've got a four- column table view set up in IB, and class files for the dataSource as follows:

// snipped

.m:
@implementation FetchHighscores

- (IBAction)fetchResults:(id)sender
{
finalData = [NSMutableArray arrayWithCapacity:4]; // To prevent it being (null)
NSString *string = @"1,1,1 2,2,2 3,3,3 4,5,6 7,3,4" // etc. Loaded from an external source.
NSArray *components = [results componentsSeparatedByString:@"\n"];
NSArray *template = [NSArray arrayWithObjects:@"Col1", @"Col2", @"Col3", @"Col4", nil];
int loops = [components count];
int loop;
for (loop = 0; loop < loops; loop++)
{
currentData = [NSMutableArray arrayWithCapacity:4];
[currentData addObject:@"0"];
[currentData addObjectsFromArray:[[scores objectAtIndex:loop] componentsSeparatedByString:@","]];
while ([currentData count] < 4) // External source isn't entirely consistent. This is just a placeholder.
{
[currentData addObject:@"0"];
}
NSDictionary *dict = [NSDictionary dictionaryWithObjects:currentData forKeys:template];
[finalScores insertObject:dict atIndex:loop];
}
[theTable reloadData];
}



// snipped

I'm getting strange errors. In the console, I get:
*** -[NSRectSet objectAtIndex:]: unrecognized selector sent to instance 0x1516c220


But sometimes I get a different error: the NSParameterAssert isn't satisfied.

What needs changing?

Thanks.

Greetings, Benjamin,

This one looks fairly easy to solve to me; when you get random errors involving classes that you're not using, it's often a memory problem. In this case, you are not retaining finalData in the -fetchResults: -- so finalData is in fact *still* null, as you're initializing it with a method that returns an autoreleased array. Try this instead:

finalData = [[NSMutableArray alloc] initWithCapacity:4]; // To prevent it being (null)

Be sure to release it somewhere, typically -dealloc.

Also, if you're using Garbage Collection, this may not hold -- but I suspect from the situation that you aren't.

Cheers,
	Andrew

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Getting started with NSTableView (From: Benjamin Dobson <email@hidden>)

  • Prev by Date: Getting started with NSTableView
  • Next by Date: Notification when window is closing?
  • Previous by thread: Getting started with NSTableView
  • Next by thread: Notification when window is closing?
  • Index(es):
    • Date
    • Thread