1

プログラムで UITableViewCell に追加しているボタンがあり、非常に奇妙な動作をしています。

iOS 6 では、期待どおりに動作します。iOS 5x では、タッチダウン イベントにのみ応答し、タッチアップ インサイド イベントには応答しません。また、タッチダウン イベントでさえ、1 ~ 2 秒間押し続けた後にのみ発生します。

//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");
}

かなり標準的な発行コード。実際、私はこの正確なコードを使用してアプリのいたるところにボタンを作成していますが、テーブル ビューを除いてすべて機能します。細胞の構造について、私が理解していないことがあるに違いありません。

4

1 に答える 1

5

わかった。ずっと前に、別の理由で UITapGestureRecognizer をテーブルに置いていました。ボタンの機能に干渉していました。みんなありがとう。(そしてギャル)

于 2012-10-29T18:57:14.563 に答える