0

私の実装では、セルにカスタムラベルを追加する必要がありました。ただし、そうすることで、カスタムラベルで覆われているセル領域がユーザーの「クリック」に反応せず、したがってメソッド「didSelectRowAtIndexPath」がトリガーされないことに気付きました。

CustomOHAttributLabel *questionLabel = [[CustomOHAttributLabel alloc]initWithFrame:CGRectMake(10, (60-labelHeight)/2, 280, labelHeight)];        

[cell.contentView addSubview:questionLabel];

カスタムラベルを追加した後でも、セル領域全体がユーザーのタッチに反応するようにする方法はありますか?

4

1 に答える 1

2

カスタムボタンを作成し、それをラベルの上に置き、onClickが同じコードを呼び出します。これを参照してください

CustomOHAttributLabel *questionLabel = [[CustomOHAttributLabel alloc]initWithFrame:CGRectMake(10, (60-labelHeight)/2, 280, labelHeight)];

UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, (60-labelHeight)/2, 280, labelHeight);
    [btn addTarget:self action:@selector(doSomeThing) forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:questionLabel];
[cell.contentView addSubview:btn];



-(void)doSomeThing
{
  //write code which you write in didSelectRowAtIndexPath method
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   [self doSomeThing];
}
于 2011-07-26T05:25:30.507 に答える