在我的iPhone应用程序中,我有SPGameDesk : UIView类,它是从其他类创建的,比如:
SPGameDesk* gameDesk = [[SPGameDesk alloc] init];
[gameDesk createWithLevel:5];
[appWindow addSubview:gameDesk];在我的SPGameDesk类的一个方法中,我创建了UIButtons
holesRow = [[NSMutableArray alloc] init];
for (int i=0; i<3; i++) {
[holesRow addObject:[[UIButton alloc] initWithFrame:CGRectMake((40*i)+5, 150, 30, 30)]];
[[holesRow objectAtIndex:i] setBackgroundColor:[UIColor blueColor]];
[[holesRow objectAtIndex:i] addTarget:self action:@selector(holeSelected:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview: [holesRow objectAtIndex:i]];
}在下面的SPGameDesk类中我有一个方法:
- (void)holeSelected:(id)sender {
NSLog(@"SELECTED");
}但是当我触摸我的按钮时,什么都不会发生,就像一些其他的UIView覆盖了我的按钮(没有其他的UIView),或者像SPGameDesk禁用了userInteraction (我选中了-它没有)。
我的问题在哪里?我应该检查什么?
发布于 2010-11-13 16:20:46
您的gameDesk视图的框架是什么?它看起来可能是0,0,0,0。尝试将其设置为父窗口的边界。使用initwithframe而不是init。
https://stackoverflow.com/questions/4170938
复制相似问题