This is probably going to be tough to explain.
Basically I have the following structure to my project:
I have an object (graph) which controls other objects (nodes) and (arcs).
Everything is working fine and dandy but I've found the need to add buttons to my node objects. This is working fine too, I have an NSLog output letting me know which node has been selected etc. My issue however is I only want one node selected at a time. The initialisation code for my node objects is as follows:
- (id) initNodeWithData:(NSString *) _label: (int) _xpos: (int) _ypos
{
if(self = [super init])
{
//other variable inits here...
[self setButton: [UIButton buttonWithType:UIButtonTypeCustom]];
[button setImage:[UIImage imageNamed:@"node.png"]
forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"node.png"]
forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"nodeSelected.png"]
forState:UIControlStateSelected];
[button setImage:[UIImage imageNamed:@"nodeSelected.png"]
forState:(UIControlStateHighlighted|UIControlStateSelected)];
[button addTarget:self
action:@selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
- (void)buttonPressed
{
NSLog(@"%@ Pressed", label);
if(button.selected == YES) button.selected = NO;
else if(button.selected == NO) button.selected = YES;
}
Because my node objects are independent form each other I can't (I don't think I can anyway) test to see if any other nodes have been selected before proceeding with selection.
Ideally I want something like:
- (void)buttonPressed
{
//Check to see if other nodes are selected
//If not, button.selected = yes
//else clear other buttons
//then select current button
}
But I think I need this code in my viewController class, where all my other code is, and I don't know how to do it because I assume it's all out of scope.
Sorry that this isn't very clear, it's difficult to explain!