【发布时间】:2014-11-15 17:33:13
【问题描述】:
我有一个TableViewController,单击自定义单元格会将您带到相关的WebViewController。
我遇到的问题是,当我点击WebViewController 中的“返回”时,TableViewController 中的表格视图单元格“跳转”。
一旦表格视图开始滚动,它们都会跳回正确的高度。所以我假设它与TableViewController 自定义单元格的高度有关,但我并不完全确定。
TableViewController.m
试过了:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[Two self]]) {
return 490; // As of 11/13/14
} else { // 2 other custom cells
return tableView.rowHeight; // return the default height
}
}
也试过了:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id model = self.Model[indexPath.row];
if ([model isKindOfClass:[One self]]) {
ListTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:@"1Cell"];
CGFloat heightOne = [cellOne.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightOne + 2;
} else if ([model isKindOfClass:[Two self]]) {
ListTableViewCellTwo *cellTwo = [tableView dequeueReusableCellWithIdentifier:@"2Cell"];
CGFloat heightTwo = [cellTwo.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightTwo + 400;
} else if ([model isKindOfClass:[Three self]]) {
ListTableViewCellThree *cellThree = [tableView dequeueReusableCellWithIdentifier:@"3Cell"];
CGFloat heightThree = [cellThree.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return heightThree + 2;
} else {
return 300;
}
}
更新:
也试过[cell setNeedsUpdateConstraints];和[cell setNeedsLayout];。
还尝试设置estimatedHeight多个不同的点,并同时添加Automatic Row Dimension。
我们将不胜感激!将发布任何需要的额外信息。谢谢!
我只支持 iOS 8。我正在使用自动布局和情节提要。
自定义单元 2 的附加故事板信息:
故事板约束:
【问题讨论】:
-
只是为了确保保持返回 490;在高度方法中并删除其他任何内容。你有什么?
-
显示 WebViewController 后是否修改了 self.Model ?
-
@hasan83 抱歉,我不确定我是否理解您的句子。您是说要删除除返回 490 之外的所有内容;?谢谢!
-
@gottlieb no self.Model 在显示 WebViewController 后根本没有修改。有什么想法吗?
-
如何添加 WebViewController ?使用 addSubview、presentViewController 还是将其推入导航堆栈?
标签: ios objective-c uitableview ios8 autolayout