繁体   English   中英

UIButton在循环中创建不可点击

[英]UIButton created in loop not clickable

这是我的问题:

我在循环中向滚动视图添加了几个按钮:

for (int i = 0; i < [allEventArray count]; i++) {

        UIButton *eventButton = [UIButton buttonWithType:UIButtonTypeCustom];
        eventButton.tag =  i + 10;

        UIImage *normalImage = [UIImage imageNamed:@"rosterButton.png"];
        normalImage = [normalImage 
                      stretchableImageWithLeftCapWidth:normalImage.size.width/2 
                      topCapHeight:normalImage.size.height/2];
        [eventButton setBackgroundImage:normalImage 
                      forState:UIControlStateNormal];

        [eventButton addTarget:self action:@selector(gotoThisAirport) 
                      forControlEvents:UIControlEventTouchUpInside];

        [drawRosterView addSubview:eventButton];
}

我稍后通过打开tag属性来设置帧大小和其他内容。 所有按钮都显示为广告。 问题是只有视图中的第一个按钮响应点击。 其他人只是坐在那里冷静,什么都不做。 怎么会这样? 它让我绝对疯狂!

请帮忙!

听起来你的UIButton并不完全在你的UIView中。

尝试仅将UIButton添加到UIView并将UIView的背景颜色设置为[UIColor greenColor] 然后,您应该看看UIButton是否部分在UIView之外。

另外,如果你在 - (void)中添加一个NSLog(“click”)调用,touchesBegan :( NSSet *)触及withEvent:(UIEvent *)事件; 如果UIView检测到触摸,您可以点击屏幕上的任意位置并获得反馈。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM