我有一個帶有自定義單元格的表格,在單元格中有兩個UIViews,最上面的一個總是顯示,而最下面的一個隱藏。表格單元格不總是在取消隱藏後顯示隱藏內容
當cellCellForRowAtIndexPath被調用時,單元格的高度都降低到只顯示頂部的UIView。
當用戶單擊單元格時,該單元格將展開,然後取消隱藏第二個UIView。問題是,有時第二個UIView不會在第一次單擊單元格時出現。
再次單擊該單元格使其全部消失,然後再次單擊並始終顯示完美。向下滾動,然後選擇另一個,然後第一次點擊它可能不會出現或將出現錯誤的地方,兩個舔,這是完美的。
我認爲這是一個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,你可以看到,但這仍然無法正常工作。這是因爲我隱藏/取消隱藏我應該做Alpha到0,然後選擇1?這是一個可重用的單元格事物嗎?
爲了完整性哦。你可能會注意到我有一張桌子,所有的高度都不同,這就是爲什麼我改變第二個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;
}
請注意,圖像是在視圖中,因爲我想添加一個標籤的負載在那裏,我不想隱藏/取消一大堆東西。 –
使用Alpha也不起作用,結果相同。 –
我禁用Y座標,它工作正常,總是在那裏。當然,問題是我需要移動它!我是否錯誤地更改Y座標? –