• 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
NSMutableArray access from other class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMutableArray access from other class


  • Subject: NSMutableArray access from other class
  • From: Davide Scheriani <email@hidden>
  • Date: Fri, 1 Feb 2008 19:44:03 +0100

hello!
ive got a Window Panel with a nice NSTableView.
I called the class "MyClass" where delegate and dataSource.
Ive got 2 colums where I have assigned the identifer as "param" and "paramValue".
Till here nothing to worry. I just implemented the delegates and the chance to edit the cells.


Ive got even two NSMutableArray and a NSDictionary.

-(id)init{
	[super init];
	params = [[NSMutableArray alloc] init];
	paramsValue = [[NSMutableArray alloc] init];

	extraDictArray = [[NSMutableDictionary alloc] initWithCapacity:2];
	[extraDictArray setObject:params forKey:@"param"];
	[extraDictArray setObject:paramsValue forKey:@"paramValue"];

	return self;
}

- (int)numberOfRowsInTableView:(NSTableView *)tableView {
	return [params count];
}

- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn
row:(int)row {
NSParameterAssert(row >= 0 && row < [params count]);
NSArray *theValue = [extraDictArray objectForKey:[tableColumn identifier]];
return [theValue objectAtIndex:row];
}


- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)tableColumn
row:(int)row {
NSString *value = [[extraParamsTable selectedCell] stringValue];

NSArray *theArray = [extraDictArray objectForKey:[tableColumn identifier]];
[theArray replaceObjectAtIndex:row withObject:value];
}


and just for the record ive got an NSTextView where I print out the param and the paramValue
so I know that it works.All the datas into the two array are added with no problem and everything works fine.
Now Ive got another class "MySecondClass", where I do want access this two NSMutableArray,
so I do this:


- (IBAction) updateParams:(id) sender{
	int row = [masterList selectedRow];
	NSLog(@">> %@",[[masterObj objectAtIndex:row] valueForKey:@"params"]);
}

what Ive got here is always an empty array..why?
call a metod (selector) inside the Panel (so the "MyClass") works, but from another class it doesnt works.
If I call another object like an NSString *test =@"hello!": like


NSLog(@">> %@",[[masterObj objectAtIndex:row] valueForKey:@"test"]);

it works..:( have no clue at all why.
and If I add some object inside the arrays outside the delegate method (ex in the init method)


-(id)init{
	[super init];
	params = [[NSMutableArray alloc] init];
	[params addObject:@"goofy1"];
	[params addObject:@"goofy2"];

	return self;
}

I get the array with the objects inside.It works.
any solutions?

tnx guys.



_______________________________________________

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


  • Prev by Date: Re: Getting an era's beginning date
  • Next by Date: Re: memory management issue?
  • Previous by thread: Re: Getting an era's beginning date
  • Next by thread: How to "capture" the mouse
  • Index(es):
    • Date
    • Thread