ilyi1116
ilyi1116

Reputation: 101

UIViewController UIButton can't touch

i have two UIViewController, A & B

[A addSubView: B.view];

it's ok.

but i got an question, i can't get the B's UIButton Touch Event after [A addSubView: B.view] why?

is anyone can help me thank you~

Here's my some code :

A View:

 CellAction_ViewController *cellActionViewController = [[CellAction_ViewController alloc] initWithNibName:@"CellAction_ViewController" bundle:nil];

 [cell.contentView addSubview:cellActionViewController.view];
 [cellActionViewController.button_like addTarget:self
                                             action:@selector(Likes_Button:)
                                   forControlEvents:UIControlEventTouchUpInside];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

B View:

- (void)viewDidLoad {
    [super viewDidLoad];

// bala bala ...
   [_button_like setClipsToBounds:YES];

}

Upvotes: 1

Views: 326

Answers (1)

user3999012
user3999012

Reputation:

It will Work.... Instead of [A.view addSubview:B.view];

Use this

[A addChildViewController:B];
[B didMoveToParentViewController:A];

Because your are adding A ViewController subview.It should be A ViewController's views sub view.

Upvotes: 2

Related Questions