In my implementation, I had to add a cust开发者_高级运维om label to the cell. However, I realize that by doing so, the cell area that is covered by the custom label will not react to the user's 'click' and hence will not trigger the method "didSelectRowAtIndexPath".
CustomOHAttributLabel *questionLabel = [[CustomOHAttributLabel alloc]initWithFrame:CGRectMake(10, (60-labelHeight)/2, 280, labelHeight)];
[cell.contentView addSubview:questionLabel];
Is there a way to allow the whole cell area to be responsive to the user's touch even after adding a Custom label to it?
Make a custom button and put that over the lavel and onClick call the same code, see this
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];
}
精彩评论