我正在以编程方式创建按钮,然后我想添加功能,当它们被点击/按下时,它们会保持突出显示,除非再次点击。我现在正在做的是创建按钮,然后尝试添加 IBAction。但是,问题是我在一个方法中创建了按钮,然后我不确定如何在我的 IBAction 中引用该按钮。这是我的代码:
UIButton* testButn = [UIButton buttonWithType:UIButtonTypeCustom];
[testButn setFrame:CGRectMake(0, 135, 40, 38)];
[testButn setImage:[UIImage imageNamed:@"test_butn_un.png"] forState:UIControlStateNormal];
[testButn setImage:[UIImage imageNamed:@"test_butn_pressed.png"] forState:UIControlStateHighlighted];
[testButn addTarget:self action:@selector(staypressed:) forControlEvents:UIControlEventTouchUpInside];
[self.contentview addSubview:testButn
-(IBAction)staypressed:(id)sender{
//Not sure what to do here, since this method doesn't recognize testButn, How do I reference testButn