我有一個類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