ios - UIViewController UIButton 不能触摸

标签 ios objective-c iphone

我有两个 UIViewController,A 和 B

[A addSubView: B.view];

没关系。

但我有一个问题,我无法在 [A addSubView: B.view] 之后获取 B 的 UIButton 触摸事件 为什么?

谁能帮帮我 谢谢~

这是我的一些代码:

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];

最佳答案

它会工作.... 代替 [A.view addSubview:B.view];

使用这个

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

因为你正在添加一个 ViewController subview 。它应该是一个 ViewController 的 View subview 。

关于ios - UIViewController UIButton 不能触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27686983/

相关文章:

ios - Sqlite 数据库不存在这样的表

iphone - 有没有办法在iPhone上获取防篡改日期和时间?

ios - 如何在 ios 6 中自定义通知 View

iphone - iOS:在 UIWebView 中从 URL 加载音频时出现问题

ios - 一次在 tableviewcell 中显示一个单词

iphone - IOS:我可以在xcode中通过恢复id获取对象吗?

objective-c - Objective-C header 中的 C 指针损坏

iphone - 查找不区分大小写的相似字符串 - iPhone

ios - 如何将 UITableViewCell 分隔符更改为自定义分隔符?

ios - 带有嵌套数组的 RestKit EntityMapping