簡體   English   中英

UITableViewCell中的UIButton在iOS 5x中不響應,但在iOS 6中響應

[英]UIButton in UITableViewCell not responding in iOS 5x but responding in iOS 6

我有一個按編程方式添加到UITableViewCell中的按鈕,它的行為非常奇怪。

在iOS 6中,它完全可以按預期運行。 在iOS 5x中,它僅響應觸地事件,而不響應觸地內部事件。 甚至按下事件僅在按住一兩秒鍾后才會觸發。

//Create UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(0, 0, 100, 100);

//Add to UITableViewCell
UITableViewCell *footerCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FOOTER_CELL"] autorelease];
[footerCell.contentView addSubview:button];
//Also tried this with just [footerCell addSubview:button];

//Fire Action
- (void)buttonTap {
    NSLog(@"Tap");
}

相當標准的發行代碼。 實際上,我使用此確切的代碼在應用程序中的各處制作了按鈕,除了在表視圖中,它們都可以正常工作。 關於單元格的結構,我有些不了解。

明白了。 很久以前,出於另一個原因,我將UITapGestureRecognizer放在桌子上。 它干擾了按鈕的功能。 多謝你們。 (和女孩)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM