如何在iOS应用中使用委托滑出菜单

时间:2015-05-04 16:42:53

标签: ios objective-c

我正在尝试使用委托调用类中的方法,但是当我调用委托方法时,应用程序崩溃时出现以下错误消息,

unrecognized selector sent to instance

我有一个滑出式菜单,其中包含一个表视图,当使用以下内容选择表视图项时,该视图正在加载视图,

// ViewControllerRootHomeLeftPanel.m
    -(void)showCalibrate{
        ViewControllerCalibrate *calibrateVC = [[ViewControllerCalibrate alloc] initWithNibName:@"ViewControllerCalibrate" bundle:nil];
        [((ViewControllerRootHome *)self.parentViewController).viewControllerRootHomeCenter addChildViewController:calibrateVC];
        [calibrateVC.view setFrame:CGRectMake(0.0f, 64.0f, self.view.frame.size.width, self.view.frame.size.height)];

        [calibrateVC didMoveToParentViewController:((ViewControllerRootHome *)self.parentViewController).viewControllerRootHomeCenter];

        [((ViewControllerRootHome *)self.parentViewController).viewControllerRootHomeCenter.view addSubview:calibrateVC.view];

    // the below delegate method hides the left panel vc (table view) after loading a view on the root home center vc.
        [myDelegate loadVCRH];
    }

然后我在ViewControllerCalibrate VC中设置了一个委托方法,

// ViewControllerCalibrate.h
@protocol ViewControllerCalibrateDelegate;
@protocol ViewControllerCalibrateDelegate <NSObject>
- (void) removeCalibrateView;
@end

@interface ViewControllerCalibrate : UIViewController
@property (nonatomic, weak) id<ViewControllerCalibrateDelegate> delegate;
@end

// ViewControllerCalibrate.m
- (void)removeCalibrateView {
    NSLog(@"removeCalibrateView method called");
}

然后我尝试在removeCalibrateView

中调用ViewControllerRootHomeCenter方法
// ViewControllerRootHomeCenter.m
- (void)removeSubViews{
    for (UIView *subview in [self.view subviews]){
        NSLog(@"subviews = %@",[self.view subviews]);
        if (subview.tag == 3) {
            // the below delegate method call is causing the app to crash.
            [self removeCalibrateView];
            [subview removeFromSuperview];
        }
    }
}

0 个答案:

没有答案