【发布时间】:2012-08-10 19:25:58
【问题描述】:
我有这个问题让我发疯。我花了几十年的时间来弄清楚为什么会这样。
我在UIView 中有一个UIScrollView 作为scrollView。在这个滚动视图中,我有三个不同的UIViews,它们是在运行时创建的。在这三个UIViews 之一中,我创建了一个按钮。这是我的代码。
UIButton *buttonLike = [UIButton buttonWithType:UIButtonTypeRoundedRect ] ;
buttonLike.frame =CGRectMake(scrollViewWidth +200, 30,36, 16);
buttonLike.imageView.image = [UIImage imageNamed:@"like.png"];
[buttonLike addTarget:self action:@selector(buttonLikePressed:) forControlEvents:UIControlEventTouchUpInside] ;
scrollViewWidth 也是一个定义和初始化的常量。
而且,我将此 buttonLike 添加为 UIViews 之一中的子视图。但是,无论我做什么, buttonLikePressed 方法都不会调用。
我已经搜索了这个问题并提出了这些解决方案。
Iphone UIButton not working in nested UIViews
iPhone SDK 2: UIButton not working in nested views loaded from nib file
他们描述了同样的问题。但是,作为一种解决方案,他们使用 -(id)initWithFrame:(CGRect)aRect 方法初始化他们的视图。好吧,我已经使用initWithFramemethod 初始化了我的UIViews。你们知道我该如何解决这个问题吗?
谢谢大家
【问题讨论】:
-
你是如何使用 initWithFrame 初始化所有这些视图的?
标签: iphone ios uiview uiscrollview