Sorry about the title being extremely vague, I'm new to Objective C and struggling a little with it. Basically I have the following section of code:
Graph *graph1 = [[Graph alloc] init];
[graph1 addNode:@"TEST"];
which is working to a degree. But I want to change it because the above code happens on a button press, and therefore I assume I am creating a new "*graph1" every time I do this. I thought I could simply change it to this:
if(self = [super init])
{
[self setGraph: [[Graph alloc] init]];
}
return self;
Where the above is in the init method, and below is the modified function:
[graph addNode:@"TEST"];
However when debugging I've found addNode method is never called when it's like this.
Thanks Zac
This is testViewController.h
#import <UIKit/UIKit.h>
@class Graph;
@class Node;
@interface testViewController : UIViewController {
Graph *graph;
UILabel *label;
}
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) Graph *graph;
- (IBAction) buttonPressed:(id)sender;
@end
This is textViewController.m
#import "testViewController.h"
#import "Graph.h"
@implementation testViewController
@synthesize label, graph;
- (id)init
{
if(self = [super init])
{
[self setGraph: [[Graph alloc] init]];
}
return self;
}
- (IBAction)buttonPressed:(id)sender
{
//Graph *graph1 = [[Graph alloc] init];
[graph addNode:@"TEST"];
Node *node1 = [[Node alloc] initWithLabel: @"LABEL"];
label.text = node1.label;
}