在你的情況,考慮MVC規則(即ü不想打破),我建議ü使用NSNotificationCenter.
所以,只要postNotification
當childView按下按鈕:
[[NSNotificationCenter defaultCenter] postNotificationName:@"buttonPressedOnChildView" object:self userInfo:nil];
而在你superView
ü應該addObserver
這樣的:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(doButtonPressedInChildView:)
name:@"buttonPressedOnChildView"
object:nil];
不要忘了在superView
添加方法:
-(void)doButtonPressedInChildView:(NSNotification*)notification {
// Do something in superView
}
在superView
viewDidDisapear:
-(void)viewWillDisppear:(BOOL)animated {
[super viewWillDisppear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
使用委派確保ü
removeObservers
。 – Vakas