• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

iOS - Button click event not workng

Community Beginner ,
May 31, 2018 May 31, 2018

Copy link to clipboard

Copied

I am building an ANE which will start a new View which contains a label and button. I was successful in adding view as bundle and view controller in my .a file.

I am starting my view as a subview. And later when I click button, it should do some stuffs and change the label text. I can display the view using below code but my button click event is not working.

--- Code to start view ---

My ViewController class name is 'VideoViewController' and bundle containing xib name is 'ViewBundle.bundle'

    UIApplication *app = [UIApplication sharedApplication];

    UIViewController *myViewController;

   

    NSBundle * mainBundle = [NSBundle mainBundle];

    NSString * pathToMyBundle = [mainBundle pathForResource:@"ViewBundle" ofType:@"bundle"];

    NSAssert(pathToMyBundle, @"bundle not found", nil);

    NSBundle *bundle = [NSBundle bundleWithPath:pathToMyBundle];

    myViewController = [[VideoViewController alloc] initWithNibName:nil bundle:bundle];

   

    [app.keyWindow addSubview:myViewController.view];

--- VideoViewController.h ---

#import <UIKit/UIKit.h>

@Interface VideoViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel *textLabel;

@property (strong, nonatomic) IBOutlet UIButton *clickBtn;

- (IBAction)BtnTapped:(id)sender;

- (IBAction)BtnTappped:(UIButton *)sender;

@End

--- VideoViewController.m ---

#import "VideoViewController.h"

@Interface VideoViewController ()

@End

@implementation VideoViewController

#pragma mark - UIViewController

- (void)viewDidLoad {

    [super viewDidLoad];

   

    [self logMessage:@"From did load"];

    [_clickBtn setUserInteractionEnabled:YES];

    [_clickBtn setTitle:@"Click Here" forState:UIControlStateNormal]; // button text changes here

}

#pragma mark - Public

- (IBAction)BtnTapped:(id)sender {

    [_textLabel setText:@"Btn Tapped"];

}

- (IBAction)BtnTappped:(UIButton *)sender {

    [_textLabel setText:@"Btn Tappped"];

}

#pragma mark - Private

- (void)logMessage:(NSString *)msg {

    NSLog(@"%@", msg);

    [_textLabel setText:msg];

}

@End

I tried to give touch event programmatically, but still button click event doesn't work.

Can anyone please help to sort out this issue?

TOPICS
Development

Views

382

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , May 31, 2018 May 31, 2018

Issue was with view initialisation. Replace [app.keyWindow addSubview:myViewController.view]; with [app.keyWindow.rootViewController presentViewController:myViewController animated:false completion:nil]; solved my issue.

Votes

Translate

Translate
Community Beginner ,
May 31, 2018 May 31, 2018

Copy link to clipboard

Copied

LATEST

Issue was with view initialisation. Replace [app.keyWindow addSubview:myViewController.view]; with [app.keyWindow.rootViewController presentViewController:myViewController animated:false completion:nil]; solved my issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines