カスタムセルを持つテーブルがあります。セルには2つのUIViewがあり、上部は常に表示され、下部は非表示になっています。
cellCellForRowAtIndexPathが呼び出されると、すべてのセルの高さが縮小され、最上位の UIView だけが表示されます。
ユーザーがセルをクリックすると、そのセルが展開され、2 番目の UIView が再表示されます。問題は、セルを最初にクリックしたときに 2 番目の UIView が表示されない場合があることです。
セルをもう一度クリックすると、すべてが消えてからもう一度クリックすると、常に完全に表示されます。下にスクロールして別のものを選択し、最初にクリックすると表示されないか、間違った場所に表示されます。さらに 2 回クリックすると完璧です。
これは ReusableCell の問題だと思いますが、回避する方法がわかりません。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cellID = @"Cell";
customCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
// Test to see if the Cell has already been built
if (cell == nil)
{
cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
// Check if the selected Cell is being drawn and unhide the pull down view and adjust y origin
if(indexPath.row == selectedCell)
{
// Unhide the view
cell.pullDownView.hidden = NO;
CGRect tempFrame = cell.pullDownView.frame;
tempFrame.origin.y = [[secondViewY objectAtIndex:indexPath.row] floatValue];
cell.pullDownView.frame = tempFrame;
// Image in second view
cell.mainImage2.image = [theImages objectAtIndex:indexPath.row];
}
else
{
cell.pullDownView.hidden = YES;
}
// Image in first view
cell.mainImage.image = [theImages objectAtIndex:indexPath.row];
return cell;
}
したがって、セルをクリックすると、次のようなdidSelectRowが呼び出されます
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedCell == indexPath.row)
{
selectedCell = -1;
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
else
{
selectedCell = indexPath.row;
}
// [tableView reloadData];
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];
}
ご覧のとおり、 reloadData と BeginUpdates の両方を試しましたが、まだ機能しません。これは、選択時にアルファを 0 にしてから 1 にする必要があるため、非表示/非表示を解除しているためですか? これは再利用可能なセルのものですか?
完全を期すためにああ。すべての高さが異なるテーブルがあることに気付くかもしれません。これが、2 番目の UIView の Y を変更する理由です。
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
float returnHeightValue;
if(indexPath.row == selectedCell)
{
returnHeightValue = [[selectedCellHeights objectAtIndex:indexPath.row] floatValue];
}
else
{
returnHeightValue = [[normalCellHeights objectAtIndex:indexPath.row] floatValue];
}
return returnHeightValue;
}