我试图从已经存在的不同类别中获取一个NSMutableArray。 但是,如果说是安全记录仪,那就是无效的。 我的节目以2级开始,然后是I segue到1级,用一个或一个以上的行文来制造我的NSMutableArray,然后我想我的班子2获得最新的NSMutable Array,但所有这些都是无效的。 法典如下:
//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]);
}
}