0

私の実装では、セルにカスタムラベルを追加する必要がありました。しかし、そうすることで、カスタムラベルでカバーされているセル領域はユーザーの「クリック」に反応せず、したがってメソッド「didSelectRowAtIndexPath」をトリガーしません。目的C:ラベルがセルに追加された場合、UITableメソッド "didSelectRowAtIndexPath"が機能しません

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

[cell.contentView addSubview:questionLabel]; 

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

+0

は、なぜあなたは小さなラベルを使用することはできません参照してください? :Oカスタムラベルの代わりにcell.textLabelを使ってみませんか? – Legolas

+0

@Legolas、私は色を変更し、テキストの一部を太字にする必要があります。私の理解からは、それを直接textLabelで行うことはできませんが、カスタムラベルを追加する必要があります。私はそれを言う権利がありますか? – Zhen

+0

これは解決するかもしれないようですhttp://stackoverflow.com/questions/6669027/uibutton-not-working-inside-uitableviewcell – Brain2000

答えて

2

カスタムボタンを作成し、lavelとの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]; 
} 
+0

このボタンはラベルを覆うか透明なボタンですか? –

+0

透明ですbutton.UIButtonTypeCustom – Ishu

関連する問題