I'm trying to access a NSMutableArray from a different already existing class than it was created in. But if i NSLog it, i get null. My program starts up in class2, then I segue to class1, create my NSMutableArray by pressing one or more rows, and then I want my class2 to get the updated NSMutableArray instance, but all it get is null. Code below:
//class1.m
#import "FocusTagTableViewController.h"
#import "STATableViewController.h"
@implementation FocusTagTableViewController
@synthesize focusArray = _focusArray;
@synthesize allSelectedFocus = _allSelectedFocus;
- (void)viewDidLoad
{
_focusArray = [[NSArray alloc]initWithObjects:@"Balance",@"Bevægelse",@"Elementskift",@"Vejrtrækning",@"Alle",nil];
[super viewDidLoad];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedFocus = [[_focusArray objectAtIndex:indexPath.row] stringByAppendingString:@","];
if(_allSelectedFocus == nil)
{
_allSelectedFocus = [[NSMutableArray alloc]init];
[_allSelectedFocus addObject:selectedFocus];
}
else if(![_allSelectedFocus containsObject:selectedFocus])
{
[_allSelectedFocus addObject:selectedFocus];
}
}
//class2.m
#import "STATableViewController.h"
#import "FocusTagTableViewController.h"
@implementation STATableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
FocusTagTableViewController *focusTag = [[FocusTagTableViewController alloc]init];
[focustag addObserver:self forKeyPath:@"allSelectedFocus" options:NSKeyValueObservingOptionNew context:NULL];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:@"allSelectedFocus"])
{
NSLog(@"%@", [object valueForKeyPath:keyPath]);
}
}