Monday, July 31, 2017

UIButton Click Not working when its triggered from static library

Leave a Comment

We are trying to trigger display button from static library project using webview. while integrating static library with single view application we have got the output design. but when we tried to attempt action by clicking on Button its not working.

Below is the code,which we have used inside cocoa touch static library

UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];  imageButton.frame = CGRectMake(self.view.frame.size.width-50, 10, 50, 50);  [imageButton setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];  imageButton.adjustsImageWhenHighlighted = NO;  // [imageButton addTarget:self  action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];  [imageButton addTarget:self action:@selector(hideWebViewBtn:) forControlEvents:UIControlEventTouchUpInside];   -(IBAction)hideWebViewBtn:(id)sender {        NSLog(@"Hide Button clicked");      [self.adView removeFromSuperview];      self.adView = nil;      return;  } 

Below is the screenshot which displayed in single view application after integration and running. Once i click on the button its not getting clicked.

enter image description here

5 Answers

Answers 1

try this,whether self button is triggering or not..

  [self.myButton sendActionsForControlEvents:UIControlEventTouchUpInside]; 

It worked for me

Answers 2

You should add your button to a super view.And also,the super view should enable user interfaces.

[yourSuperView addSubView:button];yourSuperView.userInteractionEnabled=YES;

Answers 3

How about you change your return type of your 'hideWebViewBtn' method from 'IBAction' to 'void'?

Answers 4

"Once i click on the button its not getting clicked." You mean that u click the close button,but it doesn't call the function hideWebViewBtn:() ?

Answers 5

You can try this.

UIButton *imageButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-100, 10, 50, 50)];      [imageButton setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];      [self.view addSubview:imageButton];     [self.view bringSubviewToFront:imageButton];     [imageButton removeTarget:self action:NULL forControlEvents:UIControlEventAllEvents];      [imageButton addTarget:self action:@selector(hideWebViewBtn:) forControlEvents:UIControlEventTouchUpInside]; 

Hope it works for you. Thanks!

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment