[英]View changing on UITableView update
我有一個相當復雜的形式在UITableView
布局。 此表單在表格視圖單元格中有一些UICollectionView
,還有一些選擇器顯示與日歷應用程序相同的方式:
現在,當我在我的應用程序上執行此操作時,其中一個UICollectionView
比它開始時更高 - 並且它繼續運行(我添加了一個紅色邊框以確保它是正在調整大小的UICollectionView
):
我嘗試調試UICollectionView
視圖屬性,但它永遠不會更改(並且它的getter / setter不會被調用超出我的預期) - 即使我在cellForRowAtIndexPath
上打印它確實顯示調整大小。 有什么方法可以更好地調試這個,或者有人處於相同的情況?
謝謝!
碼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//self.campos is a dictionary with sections and rows stored
NSMutableArray *infoCampos = [[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"];
NSDictionary *infoCampo = [infoCampos objectAtIndex:indexPath.row];
if ([[infoCampo objectForKey:@"nome"] isEqualToString:@"dosePorComprimido"]) {
//Remove picker cell if finds it
for (infoCampo in infoCampos) {
if ([infoCampo objectForKey:@"view"] == self.dosagemMedicamento.view) {
[infoCampos removeObject:infoCampo];
[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
return;
}
}
//Insert new cell
infoCampo = [infoCampos objectAtIndex:indexPath.row];
[infoCampos addObject:@{@"tipo":@5, @"view":self.dosagemMedicamento.view, @"nome":[infoCampo objectForKey:@"nome"]}];
[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.dosagemMedicamento.view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[pickerDosagem]|" options:0 metrics:nil views:@{@"pickerDosagem":self.dosagemMedicamento.view}]];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
UIView *view;
if ([infoCampo objectForKey:@"view"]) {
view = (UIView *) [infoCampo objectForKey:@"view"];
return view.frame.size.height;
}
return 44.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
{
UITableViewCell *cell;
NSMutableDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
UIView *view;
cell = [tableView dequeueReusableCellWithIdentifier:[[infoCampo objectForKey:@"nome"] stringByAppendingString:@"ViewLinhaCellView"] forIndexPath:indexPath];
view = [cell viewWithTag:1];
[view addSubview:[infoCampo objectForKey:@"view"]];
return cell;
}
編輯:忘了提到我沒有使用reloadData更新表視圖,而只使用reloadRowsAtIndexPaths和reloadSections來更新所需的部分/行。 所以這使得它更加怪異,因為我沒有重新加載那個特定的部分。
編輯2:添加數據源e委托代碼
我相信你的問題就在這里,在tableView:heightForRowAtIndexPath:
的實現中tableView:heightForRowAtIndexPath:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
UIView *view;
if ([infoCampo objectForKey:@"view"]) {
view = (UIView *) [infoCampo objectForKey:@"view"];
return view.frame.size.height;
}
return 44.0f;
}
視圖可能會通過自動布局或其自動調整遮罩調整大小。 這里沒有足夠的信息來確切說明原因,但是表視圖和自動布局可能會有一些有趣的行為。 我建議只返回你設置的高度,而不是從視圖中獲取高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
UIView *view;
if ([infoCampo objectForKey:@"view"]) {
if ([infoCampo objectForKey:@"viewHeight"]) {
return [[infoCampo objectForKey:@"viewHeight"] floatValue];
} else {
return 216.0f;
}
}
return 44.0f;
}
viewHeight
鍵允許您為每個單元格的視圖指定自定義高度,但此實現還返回默認高度(216),恰好是選取器視圖的標准高度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.