Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Yoda101B

macrumors newbie
Original poster
Mar 7, 2009
5
0
Hi guys,

I'm tearing my hair out! I know I'm missing something silly but I just can work it out - any help would be very gratefully received!

Basically I have a class 'Node'


Code:
@interface Node : NSObject {

	NSString	*name;
	
	NSMutableArray		*inLets;

        UIImageView  *view;
}

@property (nonatomic, retain)	NSMutableArray	*inLets;
@property (nonatomic, retain)	UIImageView  *view;
@end


Node.M

Code:
@implementation Node

@synthesize name, isRunning, hasError,inLets;

-(id) init {
	
	if (self = [super init]) {
		
		hasError = NO;
		
		self.inLets = [NSMutableArray array];
		self.outLets = [[NSMutableArray alloc] init];
		
	}
	return self;	
}


And then I have a MainViewController to display the nodes, and remembers which one is selected...
Code:
@interface MainViewController : UIViewController {


		NodeView					*currentSelection;
	
		
	}

@property (nonatomic, retain) NodeView *currentSelection;

MainViewController.M

Code:
 -(void)viewDidLoad {

	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeSelected:object:) name:@"nodeselected" object:nil];

}

-(void) nodeSelected:(NSNotification *)aNotification object:(id)object{
	
	if (nodeSelected != nil) {
			nodeSelected.isSelected = NO; 
	} else {
		
		nodeSelected = [[NodeView alloc] init];
	}
	
	NodeView *NewCurrentSelection = [[NodeView alloc] init];
	NewCurrentSelection = [aNotification object];
	
	nodeSelected = nil;
	nodeSelected = NewCurrentSelection;
	nodeSelected.isSelected = YES;
	
	
	bottomHudViewController.nameLabel.text = nodeSelected.owner.name;
	
	[bottomHudViewController showBottomHudView:(YES)];
}

The NodeView class inherits from the UIImageView class and just posts a Notification when it's clicked on....


My problem is to do with NewCurrentSelection, for some reason no matter what I do the debugger always sees the inLets array changing to a CALayerArray - which obviously no good to me?

What am I doing wrong????


Thanks very much in advance!!

Yoda
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
What is the relationship between Node and NodeView? Because the top part of your posting shows us the definition of the class Node and then the MainViewController only refers to NodeView.
 

Yoda101B

macrumors newbie
Original poster
Mar 7, 2009
5
0
In MainViewController.M

Code:
- (void) createNodeViewFromNode:(Node *)node {
	
	NodeView *nodeView = [[NodeView alloc] initWithImage: [UIImage imageNamed:@"NodeLozNormal.png"]]; 
	[nodeView setUserInteractionEnabled:YES]; 
		
	node.view = nodeView;
	nodeView.owner = node;
	
	
	[self.view addSubview:nodeView]; 
	
	[nodeView release];
	
}

But I'm not sure if thats related to my problem.... Thanks in advance
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Also, these lines of code seem curious (and are the cause of a memory leak):
Code:
NodeView *NewCurrentSelection = [[NodeView alloc] init];
NewCurrentSelection = [aNotification object];
You instantiate a new NodeView and then throw that away as you assign it aNotification's object.
 

Yoda101B

macrumors newbie
Original poster
Mar 7, 2009
5
0
Yeah they are a bit odd and have changed to...

Code:
if (nodeSelected != nil) {
			nodeSelected.isSelected = NO; 
	} 
	
	[nodeSelected release];
	
	nodeSelected = [[aNotification object] retain];
	
	nodeSelected.isSelected = YES;


I think thats right... to behonest I'm still scratching my head over when I should retain, or copy....

I've finally sorted out my other problem (after a long night!!) Looks like I accidently was alloc++init the array twice!

Thanks Though....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.