从viewcontroller移动到VC时出现崩溃

时间:2016-02-14 13:11:07

标签: ios objective-c iphone

我有一个主屏幕。我以编程方式创建了两个带动作的按钮。一个人将进入注册屏幕,另一个人将进入登录屏幕。

我添加了两个登录并注册了故事板标识。但是,当我从家庭VC移动到登录VC和注册VC时,我正在崩溃:

 -[ViewController pressSignUp:]: unrecognized selector sent to instance 0x7fbb3a72e3f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController pressSignUp:]: unrecognized selector sent to instance 0x7fbb3a72e3f0'
*** First throw call stack:

这是我的代码:

// create button 1
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-50, self.view.frame.size.width/2 , 50.0)];

    [button setBackgroundColor:[UIColor colorWithRed:188/255.0f green:155/255.0f blue:211/255.0f alpha:0.6f]];
    [button setTitle:@"Sign Up" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(pressSignUp:) forControlEvents:UIControlEventTouchUpInside];

    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // title color
    [self.view addSubview:button];

  // Button Two
   UIButton* button1 = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height-50, self.view.frame.size.width/2 , 50.0)];

   [button1 setBackgroundColor:[UIColor colorWithRed:188/255.0f green:155/255.0f blue:211/255.0f alpha:0.6f]];
    [button1 setTitle:@"Sign In" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(pressSignIn:) forControlEvents:UIControlEventTouchUpInside];

    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // title color
    [self.view addSubview:button1];

    // Border color for one button
    UIView *leftBorder = [[UIView alloc] initWithFrame:CGRectMake(0, 1, 1, button.frame.size.height)];
    leftBorder.backgroundColor = [UIColor colorWithRed:237/255.0f green:211/255.0f blue:246/255.0f alpha:0.6f];
    [button1 addSubview:leftBorder];

    -(void)pressSignUp

    {
        UIViewController *secondViewController =
        [self.storyboard instantiateViewControllerWithIdentifier:@"SignUpViewController"];
        [self presentModalViewController:secondViewController animated:YES];
        // Here You can write functionality

    }


-(void)pressSignIn

{
    UIViewController *secondViewController =
    [self.storyboard instantiateViewControllerWithIdentifier:@"SignInViewController"];
    [self presentModalViewController:secondViewController animated:YES];
    // Here You can write functionality

}

为什么我会遇到这种崩溃。有可能转移到另一个Vc。

请帮助谢谢

1 个答案:

答案 0 :(得分:1)

您忘记为发件人实施参数:

-(void)pressSignUp:(UIButton*) sender {
    }
-(void)pressSignIn:(UIButton*) sender {
    }

也许您没有在界面构建器中设置标识符:

它位于IB中的Identity Inspector选项卡下。它被称为"故事板ID"。例如:SignUpViewController