Hi I have a weird problem,
In my MainViewController class I post a notification when ever a button gets pressed
[[NSNotificationCenter defaultCenter] postNotificationName:@"step" object:nil];
in the class it self i have a observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(step) name:@"step" object:nil];
which runs the “step” method
- (void)step {
NSLog(@"works");
}
and in another class called Slide1ViewController I have a observer as well
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSLog(@"works 2");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(step) name:@"step" object:nil];
}
return self;
}
and the dealloc method removes it
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"step" object:nil];
}
In the MainViewController the method gets called, but never in the Slide1ViewController.
The Slide1ViewController gets initialized like that:
Slide1ViewController*test = [[Slide1ViewController alloc] initWithNibName:@"Slide1ViewController" bundle:nil];
test.view.frame = CGRectMake(1024*0, 0, 1024, 768);
[contentScrollView addSubview:test.view];
Thanks a lot to @Phillip Mills you were right i needed to declare it as @property of MainViewController now it works !!! Big Thanks this problem was driving me crazy.