0

我在 Objective C 中创建一个应用程序,当我按下应用程序中的按钮时收到运行时错误。这是创建按钮的代码。是的,在有人问之前,我必须使用编码版本。

extend = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //3
[extend setFrame:CGRectMake(100, 50, 75, 50 )];
[extend setTitle:@"Extend" forState:UIControlStateNormal];
[extend addTarget:self action:@selector(extendPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:extend];
[self.view bringSubviewToFront:extend];

retract = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //3
[retract setFrame:CGRectMake(100, 110, 75, 50 )];
[retract setTitle:@"Retract" forState:UIControlStateNormal];
[extend addTarget:self action:@selector(retractPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:retract];
[self.view bringSubviewToFront:retract];

这是行动。

- (IBAction)extendPressed:(UIButton *)sender{

    NSLog(@"Extend");

}

- (IBAction)retractPressedPressed:(UIButton *)sender{

    NSLog(@"Retract");

}

当我按下 Retract 按钮时,什么也没有发生,但是当我按下 Extend 按钮时,应用程序崩溃,这会显示在调试控制台中:

2013-07-31 16:57:49.479 驱动器 3.0[1557:907] 扩展 2013-07-31 16:57:49.482 驱动器 3.0[1557:907]-[driveViewControllerretractPressed:]:无法识别的选择器发送到实例 0x1f564730 2013- 07-31 16:57:49.483 Drive 3.0[1557:907] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[driveViewControllerretractPressed:]:无法识别的选择器发送到实例 0x1f564730”*第一次抛出调用堆栈:( 0x33c9e3e7 0x3b999963 0x33ca1f31 0x33ca064d 0x33bf8208 0x35b98087 0x35b9803b 0x35b98015 0x35b978cb 0x35b97db9 0x35ac05f9 0x35aad8e1 0x35aad1ef 0x377c55f7 0x377c5227 0x33c733e7 0x33c7338b 0x33c7220f 0x33be523d 0x33be50c9 0x377c433b 0x35b012b9 0x1a229 0x19f88) libc++abi.dylib: terminate called throwing an exception

提前感谢任何能够帮助并告诉我我做错了什么的人。

4

1 回答 1

2

您的方法名称中有错字:

retractPressedPressed

应该只是:

retractPressed
于 2013-07-31T21:03:40.113 回答