UpientView Updateの変更を表示します
-
21-12-2019 - |
質問
私は一般的な形式の形式が一般的な創造的な形式で配置されています。このフォームには、テーブルビューセルの中にいくつかのUITableView
があり、カレンダーアプリでも同じように表示されるいくつかのピッカーがあります。
今私が私のアプリでこれを行うとき、私がそれがどのように起動したかより高いUICollectionView
の1つが高くなり、それが行くのを続けます(私はそれがサイズ変更されていたことを確認するために赤い境界線を追加しました):
UICollectionView
Viewプロパティをデバッグしようとしましたが、変更されたことはありません(そしてそれは私が予想以上に呼ばれていません) - UICollectionView
に印刷すると、サイズ変更が表示されます。私がこのより良いデバッグをすることができる、または誰かが同じ状況にあることができる方法はありますか?
ありがとう!
コード:
- (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を使用して必要なセクション/行だけです。それで私はその特定のセクションを再ロードしていないので、それをWeirderさえします。
編集2:追加されたデータソースEデリゲートコード
解決
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)も返します。