UIViewController子类,转发委托消息

时间:2014-01-18 20:02:34

标签: ios iphone objective-c uiviewcontroller delegates

我有UIViewController子类,我在其中实现了一个委托,然后在我的childviewcontrollers(从子类继承的viewcontrollers)中实现委托方法,但是我从未收到过消息,只有当我直接实现委托方法时子类/父视图控制器。我已经将委托设置为self,从另一个viewcontroller,为segue做准备。

·H

@interface aViewController : UIViewController 
@property (nonatomic, weak) id <ModalViewDelegate> presentDelegate;
@end

的.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"ToView"]) {
        UITabBarController *tabBarController = segue.destinationViewController;
        for (UINavigationController *navController in tabBarController.viewControllers) {
            for (UIViewController *vc in navController.viewControllers) {
                if ([vc isKindOfClass:[SVC class]]){
                    self.SubclassVC = (SVC*) vc;
                    if ([self respondsToSelector:@selector(setPresentDelegate:)]) {
                        self.presentDelegate = self.SubclassVC;
                    }

                    if ([self.SubclassVC respondsToSelector:@selector(setDismissDelegate:)]) {
                        self.SubclassVC.dismissDelegate = self;
                    }
                }
            }
        }
    }
}

@interface SVC : UIViewController <ModalViewDelegate>
@end

@implementation SVC
- (void)didPresentModalViewFrom:(UIViewController *)viewController {
// I recieve a message. Does work // How to forward this to childviewcontrollers?  
}
@end

@interface B : SVC
@end

@implementation B
- (void)didPresentModalViewFrom:(UIViewController *)viewController {
// Does not work
}

@end

如何让childviewcontroller(从SVC继承的viewcontrollers)响应委托方法?

0 个答案:

没有答案