2013-04-09 94 views
0

请帮助..我有我的子类,当我addsubview它在我UIView这个按钮,它不能被点击,任何想法..感谢按钮中的UIView不能点击

在我的子键:

- (void)configureDate{ 
    ChangeButton=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    ChangeButton.frame= CGRectMake(10, 20, 100, 30); 
    [ChangeButton setTitle:@"Change Date" forState:UIControlStateNormal]; 
    [ChangeButton addTarget:self action:@selector(changeDate) forControlEvents:UIControlEventTouchUpInside]; 
    [self addSubview:ChangeButton]; 
} 

我在我的UIView添加的子类/按钮:

dateClass = [[DateClass alloc] init]; 
[dateClass configureDate]; 
[myView addSubview:dateClass]; 
[dateClass releaseTable]; 

按钮上显示,但无法点击:(

+2

你真的不应该使用变量名的初始大写字母。大写首字母用于表示类别名称。你是否将'myView.userInteractionEnabled'设置为NO?如果这样会导致这个问题。另外,dateClass是什么?它是NSDate的子类吗? – Fogmeister 2013-04-09 08:13:36

+0

你确定你的父视图的框架是正确的吗? – 2013-04-09 08:14:47

+0

检查dateClass视图或ChangeButton的顶部,其他任何视图都添加为叠加。以及上述检查。 – 2013-04-09 08:16:10

回答

-1

试试这个:

[myView addSubview:dateClass]; 
[myView bringSubviewToFront:dateClass]; 

试着为dateClass和ChangeButton按钮设置BG颜色来测试。

- (void)configureDate{ 
ChangeButton=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
ChangeButton.frame= CGRectMake(10, 20, 100, 30); 
[ChangeButton setTitle:@"Change Date" forState:UIControlStateNormal]; 
[ChangeButton addTarget:self action:@selector(changeDate) forControlEvents:UIControlEventTouchUpInside]; 
[self addSubview:ChangeButton]; 
self.backgroundColor=[UIColor redColor]; 
ChangeButton.backgroundColor=[UIColor yellowColor]; 

}