0

I can't understand why the selector is not called.

//EDITED

[self.scrollView setContentSize:CGSizeMake(320, 600)];        

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn addTarget:self 
            action:@selector(validateTextFields:) 
            forControlEvents:UIControlEventTouchUpInside];

    [btn setTitle:@"Продължи" forState:UIControlStateNormal];
    btn.frame = CGRectMake(55, 580, 210, 50);
    [self.scrollView addSubview:btn];



-(IBAction)validateTextFields:sender
{
    NSLog(@"Called");
}

When I touch the button "Called" is not logged in console. If I change UIControlEventTouchUpInside to UIControlEventTouchDown validateTextFields method is executed.

foho
  • 779
  • 9
  • 20
  • overlap any another view to button? – Hector Mar 07 '12 at 10:59
  • You aren't showing any code where you add the button to a view. Have you done this or are you getting it confused with a button from a nib? – Jim Mar 07 '12 at 11:08

3 Answers3

1

You are adding a button on UIScrollView, this might be creating problem. Please check this question: iPhone: adding button to scrollview makes button inaccessible to interaction. It may be helpful.

Community
  • 1
  • 1
san
  • 3,350
  • 1
  • 28
  • 40
0

The type for action should be

- (IBAction)validateTextFileds:(id)sender
{
   // do your stuff
}

and your @selector parameter in addTarget should look like this: @selector(validateTextFields:)

Nava Carmon
  • 4,523
  • 3
  • 40
  • 74
  • I made the changes you suggest, but with no luck. When the button is set to UIControlEventTouchUpInside -(IBAction)singleTap:(id)sender is not executed. – foho Mar 07 '12 at 11:02
  • 1
    That's not true in iOS, there are [multiple method signatures](https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW44) you can use. – Jim Mar 07 '12 at 11:05
  • And if you to connect your button from IB for same type of events do you get the tap? May be your view is overlapped with another view so you don't get touch events? @Jim, you're right, I probably is behind the technology :), since it not always was like that – Nava Carmon Mar 07 '12 at 11:17
-1

try this:

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

-(IBAction)buttonPressed:(id)sender{  
 }
jahan
  • 124
  • 2
  • 11