【问题标题】:Error calling action for button in Objective C在 Objective C 中调用按钮的操作时出错
【发布时间】:2013-07-31 20:59:47
【问题描述】:

我在 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 Drive 3.0[1557:907]-[driveViewControllerretractPressed:]:无法识别的选择器发送到实例 0x1f564730 2013-07-31 16:57:49.483 驱动器 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:终止调用抛出异常

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

【问题讨论】:

    标签: ios objective-c uibutton action programmatically-created


    【解决方案1】:

    你的方法名有错别字:

    retractPressedPressed
    

    应该是:

    retractPressed
    

    【讨论】:

    • 不用担心,有时只需要一双新鲜的眼睛!
    猜你喜欢
    • 2017-05-21
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多