UIButton Click Does Not Work When It Launches From the Static Library

We are trying to call the display button from a static library project using webview. integrating a static library with one view, we get an output construct. but when we tried to perform the action by pressing the "Button" button, it does not work.

Below is the code we used inside cocoa to touch the 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 a screenshot that appears in the application with one view after integration and launch. As soon as I press the button, they don’t press it.

enter image description here

+5
source share
5 answers

try this whether the button itself starts or not.

  [self.myButton sendActionsForControlEvents:UIControlEventTouchUpInside]; 

It worked for me

+2
source

You must add your button to the superview. In addition, superview should include user interfaces.

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

+1
source

How about changing the type of the "hideWebViewBtn" method you are returning from "IBAction" to "void"?

0
source

"As soon as I press the button, they don’t press it." You mean that you click the close button, but it does not call the hideWebViewBtn function :()?

0
source

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 this works for you. Thanks!

0
source

Source: https://habr.com/ru/post/1269981/


All Articles