スクロールビューを使用したソリューションでは、gestureRecognizerがタッチを取得するため、スクロールビューでスクロールすることはできません。そのため、私はスクロールビューをまったく使用しません。
次のように、ラベルのサイズをコンテンツに合わせて変更します。
CGSize customTextLabelSize = [cell.customTextLabel.text sizeWithFont:cell.customTextLabel.font constrainedToSize:CGSizeMake(cell.customTextLabel.frame.size.width, 999999)];
cell.customTextLabel.frame = CGRectMake(cell.customTextLabel.frame.origin.x, cell.customTextLabel.frame.origin.y, cell.customTextLabel.frame.size.width, customTextLabelSize.height);
また、heightForRowAtIndexPathにこれを実装する必要があります
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGSize cellSize = [bigTextString sizeWithFont:customTextLabel.font constrainedToSize:CGSizeMake(generalCellWidth, 999999)];
return cellSize.height;
}
このようにして、didSelectRowAtIndexメソッドを使用できます。
本当にスクロールビューを使用したい場合は、cellForRowAtIndexPath:メソッドのセルにボタンを追加します。ボタンをセルと同じ大きさにし、次のようなボタンタグを追加します。
UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeCustom];
cellButton.frame = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height);
cellButton.tag = indexPath.row;
[cellButton addTarget:self action:@selector(cellButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:cellButton];
それから加えて:
-(void)cellButtonAction:(UIButton*)sender
{
//do something with sender.tag
}