的兩個情景在這裏:當對象A的兩倍
2)對象B永遠只能通過一組屬性和對象A需要Bethod稱爲
1)對象B可能有傳遞給它不同的屬性B1和B2在ObjectB保持相同屬性時運行。
3)如果對象B需要傳遞給它的新參數,請使用getters和setters?
方案1:
ObjectA.m:
...
ObjectB *objectB = [[ObjectB alloc] initWithSomeParameter:@"the parameter"];
NSString *callback1 = [objectB methodB1];
// why release when you can repoint?
ObjectB *objectB = [[ObjectB alloc] initWithSomeParameter:@"another parameter"];
NSString *callback2 = [objectB methodB2];
[objectB release];
方案2:
ObjectA.m:
...
ObjectB *objectB = [[ObjectB alloc] initWithSomeParameter:@"the parameter"];
NSString *callback1 = [objectB methodB1];
NSString *callback2 = [objectB methodB2];
[objectB release];
方案3:
ObjectA.m :
...
ObjectB *objectB = [[ObjectB alloc] initWithSomeParameter:@"the parameter"];
NSString *callback1 = [objectB methodB1];
[objectB setSomeParameter:@"another parameter"];
NSString *callback2 = [objectB methodB2];
[objectB release];
當你說ObjectB回調?我希望你不是說:
ObjectA.m:
ObjectB *objectB = [[ObjectB alloc] initWithSomeParameter:@"the parameter"];
NSString *callback1 = [objectB methodB1];
...
對象B。L:
...
//DO some work in method B1
ObjectA *objectA [[ObjectA alloc] init];
[objectA callback];
這是一個記憶領先籠罩在你那裏,然後......如果這是你的意思,那麼我建議看我上面的場景的或看NSNotificationCentre通知交叉對象通知,即回調。
顯示實際代碼並給出例外的詳細信息(名稱,消息,堆棧跟蹤/位置)。 – Wain