我有一个类A(监听器),在他的init方法观察了通知和实例化和膨胀一个NSMutableArraypostNotification访问观察者
的不同实例当类B(发件人)讯息至观察者的通知的类, 它正确地调用方法内的选择器中声明的方法我的实例变量NSMutableArray指向0x000000
可能通知运行在一个不同的istance类?我可以解决买声明作为一个Singleton
@implementation ClassA
@synthesize myArray;
-(id) init {
if (self = [super init]){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(methodThatGetsCalled:)
name:@"dispatchMethods"
object:nil];
classB = [[ClassB alloc] init];
}
return self;
}
- (void)anotherClassAMethod {
// first i populate my array
myArray = [[NSMutableArray alloc] initWithArray:eventsArray];
// than i call Class B
}
- (void)methodThatGetsCalled:(NSNotification)note {
// when the notification is posted, this method gets called but...
myArray; //points to 0x000000 here
}
实例化之前打到
methodThatGetsCalled:
您可以发布您的init方法吗? – yonosoytu也许你错过了这个变量。让我们看看一些代码! – Groot
完成,最干净的可能 – Zerho