我有3個控制器排隊,如我的3個控制器是ControllerA,ControllerB和ControllerC。在viewWillDisappear中控制委託方法調用
- ControllerA navigates to ControllerB.
- ControllerB can navigate to ControllerA (using Back Button) and can navigate to ControllerC.
- ControllerC can navigate to ControllerB.
我在ControllerB的協議,並委託其實施是ControllerA。
ControllerB.h
@protocol ControllerBDelegate <NSObject>
- (void)someMethod;
@end
ControllerB.m
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.delegate someMethod];
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ControllerC *controllerC = [[ControllerC alloc] init];
[controllerC navigateToView];
}
ControllerA.h
@interface ControllerB : UITableViewController <ControllerADelegate>
@end
ControllerA.m
- (void)someMethod
{
// Some method and its implementation logic.
}
問: 當我點擊返回上ControllerB按鈕,viewWillDisappear被調用,並執行內部的邏輯 '的someMethod()'在ControllerA中根據需要定義。但是當我點擊一個單元格導航到ControllerC時,由於ControllerB正在消失,這次它調用viewWillDisappear並執行ControllerA中定義的'someMethod()'內部的邏輯,然後導航到ControllerC。
有沒有一種方法可以避免在ControllerB中執行或viewWillDisappear,以避免在導航到ControllerC時調用someMethod()。總之,當我導航到ControllerC時,我不希望ControllerB調用並執行someMethod()。