iPhone,转换@Selector调用IBAction

时间:2013-10-22 15:44:00

标签: ios uibutton selector ibaction

我有这段代码:

UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *imgIcon = imageNamed(@"icon_1.png");
[btn1 setImage:imgIcon forState:UIControlStateNormal];

CGPointMake(textField.frame.size.width+textField.frame.origin.x+btnTalk.frame.size.width/2, textField.frame.origin.y+textField.frame.size.height/2);
[btnTalk addTarget:textField action:@selector(Hello:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:btnTalk];

我可以点按UI按钮,它可以正常工作 但我想用其他按钮打电话 我想创建一个IBAction来调用这个UIButton

我写这段代码但不起作用& textfield是(objectOfAnotherClass)

-(IBAction)call1
{
    [textField Hello];
}

2 个答案:

答案 0 :(得分:0)

我认为您正在寻找可以帮助您“模拟”触摸按钮的动作的sendActionsForControlEvents ... Here方法说明。

答案 1 :(得分:0)

我认为你应该这样做:

[btnTalk addTarget:self action:@selector(Hello:) forControlEvents:UIControlEventTouchUpInside];

-(IBAction)call1
{
   [self Hello:nil];
}