-1

我有什么办法可以解决它。

  NavigationControllerWithSlider* controller = (NavigationControllerWithSlider*) self.ViewLocations;    // ViewLocations ----> subView of ViewController && NavigationControllerWithSlider is a ViewController .


 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setRightSlidingViewWithSliderImage:length:]: unrecognized selector sent to instance 0x805df60'
*** First throw call stack:
(0x1bec012 0x1508e7e 0x1c774bd 0x1bdbbbc 0x1bdb94e 0x19f7c 0x90d1c7 0x90d232 0x90d4da 0x9248e5 0x9249cb 0x924c76 0x924d71 0x92589b 0x925e93 0x925a88 0xb9a6 0xb3e8 0xaf40 0x8db285 0x8db4ed 0x44c5b3 0x1bab376 0x1baae06 0x1b92a82 0x1b91f44 0x1b91e1b 0x1b467e3 0x1b46668 0x82bffc 0x86dd 0x22b5)
libc++abi.dylib: terminate called throwing an exception
(lldb)

这是我的代码:

//ViewController.m

NavigationControllerWithSlider* controller = (NavigationControllerWithSlider*) self.ViewLocations;    // ViewLocations ----> subView of ViewController
    UIImage * img = [UIImage imageNamed: @"open_panel.png"];
    UIImage * closeImg = [UIImage imageNamed: @"close_panel.png"];

    UIImage * img1 = [UIImage imageWithCGImage:img.CGImage scale:img.scale orientation:UIImageOrientationUpMirrored];
    UIImage * closeImg1 = [UIImage imageWithCGImage:closeImg.CGImage scale: closeImg.scale orientation:UIImageOrientationUpMirrored];

    [controller setRightSlidingViewWithSliderImage:img1 length:300.0f];
    controller.rightSlidingViewControllerId = @"toBeEmbeddedRight";
    controller.rightSlidingView.hideSliderImage = closeImg1;
    controller.rightSlidingView.headPadding = 44.0f;
    controller.rightSlidingView.trailPadding = 44.0f;

//NavigationControllerWithSlider.m

- (void) setRightSlidingViewWithSliderImage: (UIImage*) image length: (CGFloat) length {
    _rightSlidingView = [[SlidingViewController alloc] initWithPosition: DDSliderPositionRight image: image length: length];
    _rightSlidingViewControllerId = @"";
}

我在这里缺少什么..?任何帮助请......

4

2 回答 2

1

You are casting an object to NavigationControllerWithSlider, but my guess is that object is not really a NavigationControllerWithSlider. Can you add a log in above calling setRightSlidingViewWithSliderImage

NSLog(@"Class of controller: %@", NSStringFromClass([controller class]));

(or just let us know what self.ViewLocations is declared as)

于 2013-04-29T09:37:01.713 回答
1

因此,您必须将 NavigationControllerWithSlider 的实例显式设置为客户端视图控制器。为此,您可以使用以下方法或类似方法:

@interface NavigationControllerWithSlider : UINavigationController

// some custom interface
// ..

- (void)setRightSlidingViewWithSliderImage:(UIImage *)image length:(CGFloat)length;

@end

// this is the main controller with strong property of NavigationControllerWithSlider instance
@interface MainRootViewController

@property (nonatomic, strong) NavigationControllerWithSlider *sliderController;

@end

@implementation MainRootViewController

- (id)init {
    self = [super init];
    if (self) {
        _sliderController = [NavigationControllerWithSlider new];
    }

    return self;
}

- (void)presentPopup {
    SomeController *newControllerForPopup = [[SomeController alloc] init];
    newControllerForPopup.sliderController = self.slider;

    // present controller and use slider ^ that you've set here explicitly
}

@end

// here is an example of using and declaring of public property
@interface SomeController : UIViewController

@property (nonatomic, weak) NavigationControllerWithSlider *sliderController;

@end

@implementation SomeController

- (void)viewDidLoad {
    [super viewDidLoad];

    // do some additional view configuration using self.sliderController
}

@end
于 2013-04-29T10:21:07.053 回答