ios - 覆盖 IOS UIButton 按钮按下

标签 ios objective-c uibutton uikit

我有一个来自 viewDidLoad 的 ViewController.m 文件:

_registerButton = [AuthButton buttonWithType:UIButtonTypeSystem];
[_registerButton setTitle:@"Register" forState:UIControlStateNormal];
_registerButton.frame = CGRectMake(0.0, 0.0, self.screenWidth / 2.0 - 1.0, 60.0);

[_registerButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

...

 (IBAction)buttonPressed:(UIButton *)sender
{
    //sentder.titleLabel
    [sender setTitle:@"Registers" forState:UIControlStateNormal];
} 

registerButton 是通过属性声明的 AuthButton。如何覆盖buttonPressed并将我的IBAction代码移动到我的AuthButton.m类?对语法感到困惑(objective-c 的新手)。

最佳答案

addTarget 属性就是您所需要的。在您的示例中,目标是 self,因此按钮按下事件会在当前对象中查找选择器。

如果将目标更改为 AuthButton 实例,并在 AuthButton.m 中编写相应的选择器,应该没问题。

关于ios - 覆盖 IOS UIButton 按钮按下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18734639/

相关文章:

ios - Objective C,base64 png 到 UIImage

iOS倒计时显示隐藏按钮

ios - 如何在 Objective c 中处理 TableviewCell 中的 UIButton?

ios - UIButton 在 UIScrollView 的初始框架外不可点击

ios - 如何在没有 Apple 开发者帐户的设备上运行应用程序

iphone - iphone 应用程序 Beta 测试人员需要开发者许可证吗?

iphone - 将数组中的值设置为零

iphone - Objective-C 中的私有(private)变量是否强大?

ios - 错误 : "No visible @interface for ' UIAlertView' declares the selector 'initWithTitle'

ios - 在 Swift 中使用 animateWithDuration 自定义 UIViewController 转换