簡體   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