gpt4 book ai didi

ios - 从 viewcontroller 移动到 VC 时崩溃

转载 作者:行者123 更新时间:2023-11-29 01:14:28 25 4
gpt4 key购买 nike

我有一个主屏幕。我以编程方式创建两个带有 Action 的按钮。一个将转到注册屏幕,另一个将转到登录屏幕。

我添加了登录和注册 Storyboard身份。但是,当我从那个家庭 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。

请帮忙谢谢

最佳答案

您忘记为发送者实现参数:

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

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

它位于 IB 中的身份检查器选项卡下。它被称为“ Storyboard ID”。例如:SignUpViewController

关于ios - 从 viewcontroller 移动到 VC 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35392165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com