I think you should do like this:
[btnTalk addTarget:self action:@selector(Hello:) forControlEvents:UIControlEventTouchUpInside];
-(IBAction)call1
{
[self Hello:nil];
}
Question
I have this code:
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];
i can tap in UIbutton and it works but i want to call with other button i want create one IBAction for call this UIButton
i writes this code but doesn't work & textfield is (objectOfAnotherClass)
-(IBAction)call1
{
[textField Hello];
}
Solution
I think you should do like this:
[btnTalk addTarget:self action:@selector(Hello:) forControlEvents:UIControlEventTouchUpInside];
-(IBAction)call1
{
[self Hello:nil];
}
OTHER TIPS
I think that you are looking for sendActionsForControlEvents
that helps you to 'simulate' the action of touching the button... Here the method description.