iOS - NavController 和自定义视图

发布于 2024-11-28 07:18:41 字数 4130 浏览 1 评论 0原文

崩溃:

-[UIImageView setParentViewController:]:无法识别的选择器发送到实例 0x58701e * 由于未捕获的执行“NSInvalidArgumentExecption”而终止应用程序,原因:“-[UIImageView setParentViewController:]: 无法识别的选择器发送到实例 0x58701e0”

当我尝试推送制作的自定义 UIViewController 时,会发生这种情况没有IB。

当我用 IB 这样做时,它有效,但并不完全是我所需要的。

我的代表需要做什么

-(void)switchToTrailerOne 
{
CGsize screenSize = [UIScreen mainScreen].bounds.size;
CGRect screenBounds = CGRectMake(0, 0, ScreenSize.width, screenSize.height);
TrailersViewController *trailersController = [[TrailersViewController alloc] initWithFrame:screenBounds];

[self.navController pushViewController:trailersController animated:NO]; (Crashes on this line)

[trailersController gotoFirstTrailer];
}

询问我是否有任何其他代码,看起来我几乎从来没有离开过一次超过一个小时。

编辑:这些文件有点长,您对哪些特定部分感兴趣?我将发布一些我认为可能的候选人......

-(void)loadView{

    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    CGRect screenBounds = CGRectMake(0, 0, screenSize.width, screenSize.height);
    myTrailersView = [[UIImageView alloc] initWithFrame:screenBounds];
    myTrailersView.autoresizesSubviews = YES;
    self.view = myTrailersView;
}

//Initiation Method
- (void)viewDidLoad {
    [super viewDidLoad];

    //self.myTrailersView.frame = self.view.frame;

    //Turn User Interaction ON - UI Image Views are Off By Default
    myTrailersView.userInteractionEnabled = YES;

    //Set Position Counters to starting values
    currentNode              = 0;
    currentPosition          = 0;

    //Allocate the Node Collection
    nodeCollection           = [NodeSet alloc];

    //Copy the Node Collection to the Receiver Array
    nodeArray                = nodeCollection.createNodeList;

    //Done With Node Collection Release it
    [nodeCollection release];

    //
    //Create the button that launches the cutaway view
    //
    UIBarButtonItem *rotationButton = [[UIBarButtonItem alloc] initWithTitle:@"Cutaway View" 
                                                                       style:UIBarButtonItemStylePlain 
                                                                      target:self 
                                                                      action:@selector(gotoRotationView)];
    self.navigationItem.rightBarButtonItem = rotationButton;
    [rotationButton release];

    ////////Setup the Swipe Forward Recognizer////////

    UISwipeGestureRecognizer *recognizerUp;

    recognizerUp             = [[UISwipeGestureRecognizer alloc]
                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    [recognizerUp setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [myTrailersView addGestureRecognizer:recognizerUp];
    [recognizerUp release];

    ////////Setup the Swipe Backward Recognizer////////

    UISwipeGestureRecognizer *recognizerDown;

    recognizerDown            = [[UISwipeGestureRecognizer alloc] 
                                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    recognizerDown.direction  = UISwipeGestureRecognizerDirectionDown;
    [myTrailersView addGestureRecognizer:recognizerDown];
    [recognizerDown release];

    ////////Setup the Swipe Left Recognizer////////

    UISwipeGestureRecognizer *recognizerLeft;

    recognizerLeft            = [[UISwipeGestureRecognizer alloc] 
                                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    recognizerLeft.direction  = UISwipeGestureRecognizerDirectionLeft;
    [myTrailersView addGestureRecognizer:recognizerLeft];
    [recognizerLeft release];

    ////////Setup the Swipe Right Recognizer////////

    UISwipeGestureRecognizer *recognizerRight;

    recognizerRight           = [[UISwipeGestureRecognizer alloc] 
                                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    recognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
    [myTrailersView addGestureRecognizer:recognizerRight];
    [recognizerRight release];
}

- (id)initWithFrame:(CGRect)frame {
    self = [super.view initWithFrame:frame];

    return self;
}

The Crash:

-[UIImageView setParentViewController:]: unrecognized selector sent to instance 0x58701e
* Termintating app due to uncaught execption 'NSInvalidArgumentExecption', reason: '-[UIImageView setParentViewController:]: unrecognised selector sent to instance 0x58701e0'

This occurs when I'm trying to push a custom UIViewController that is made without IB.

When I do this with IB it works but it's not exactly what I need.

What is being called for my delegate

-(void)switchToTrailerOne 
{
CGsize screenSize = [UIScreen mainScreen].bounds.size;
CGRect screenBounds = CGRectMake(0, 0, ScreenSize.width, screenSize.height);
TrailersViewController *trailersController = [[TrailersViewController alloc] initWithFrame:screenBounds];

[self.navController pushViewController:trailersController animated:NO]; (Crashes on this line)

[trailersController gotoFirstTrailer];
}

Ask me about any other code that looks as I'm almost never away from a comp for more then an hour at a time.

Edit: The files are a bit long any particular sections you're interested in? I'll post a few canidates that I find likely...

-(void)loadView{

    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    CGRect screenBounds = CGRectMake(0, 0, screenSize.width, screenSize.height);
    myTrailersView = [[UIImageView alloc] initWithFrame:screenBounds];
    myTrailersView.autoresizesSubviews = YES;
    self.view = myTrailersView;
}

//Initiation Method
- (void)viewDidLoad {
    [super viewDidLoad];

    //self.myTrailersView.frame = self.view.frame;

    //Turn User Interaction ON - UI Image Views are Off By Default
    myTrailersView.userInteractionEnabled = YES;

    //Set Position Counters to starting values
    currentNode              = 0;
    currentPosition          = 0;

    //Allocate the Node Collection
    nodeCollection           = [NodeSet alloc];

    //Copy the Node Collection to the Receiver Array
    nodeArray                = nodeCollection.createNodeList;

    //Done With Node Collection Release it
    [nodeCollection release];

    //
    //Create the button that launches the cutaway view
    //
    UIBarButtonItem *rotationButton = [[UIBarButtonItem alloc] initWithTitle:@"Cutaway View" 
                                                                       style:UIBarButtonItemStylePlain 
                                                                      target:self 
                                                                      action:@selector(gotoRotationView)];
    self.navigationItem.rightBarButtonItem = rotationButton;
    [rotationButton release];

    ////////Setup the Swipe Forward Recognizer////////

    UISwipeGestureRecognizer *recognizerUp;

    recognizerUp             = [[UISwipeGestureRecognizer alloc]
                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    [recognizerUp setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [myTrailersView addGestureRecognizer:recognizerUp];
    [recognizerUp release];

    ////////Setup the Swipe Backward Recognizer////////

    UISwipeGestureRecognizer *recognizerDown;

    recognizerDown            = [[UISwipeGestureRecognizer alloc] 
                                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    recognizerDown.direction  = UISwipeGestureRecognizerDirectionDown;
    [myTrailersView addGestureRecognizer:recognizerDown];
    [recognizerDown release];

    ////////Setup the Swipe Left Recognizer////////

    UISwipeGestureRecognizer *recognizerLeft;

    recognizerLeft            = [[UISwipeGestureRecognizer alloc] 
                                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    recognizerLeft.direction  = UISwipeGestureRecognizerDirectionLeft;
    [myTrailersView addGestureRecognizer:recognizerLeft];
    [recognizerLeft release];

    ////////Setup the Swipe Right Recognizer////////

    UISwipeGestureRecognizer *recognizerRight;

    recognizerRight           = [[UISwipeGestureRecognizer alloc] 
                                    initWithTarget:self action:@selector(handleSwipeFrom:)];

    recognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
    [myTrailersView addGestureRecognizer:recognizerRight];
    [recognizerRight release];
}

- (id)initWithFrame:(CGRect)frame {
    self = [super.view initWithFrame:frame];

    return self;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不是你的备胎 2024-12-05 07:18:41

看起来好像您正在尝试推送自定义 UIView 而不是自定义 UIViewController。检查 TrailersViewController 类层次结构。

It's appears as if you're trying to push a custom UIView rather than a custom UIViewController. Check the TrailersViewController class hierarchy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文