【问题标题】:UITableView looks right in simulator and wrong in actual device - iPhone 4sUITableView 在模拟器中看起来正确而在实际设备中看起来错误 - iPhone 4s
【发布时间】:2015-09-04 12:41:10
【问题描述】:

我有一个UITableView,它可以在模拟器和除 iPhone 4s 之外的所有设备中正常加载。我一直在寻找答案,甚至一直搁置到现在,希望我能想到一个解决方案,但似乎没有任何效果。

我尝试的解决方案是删除可能的冲突代码,现在注释如下。

// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
    //[cell setSeparatorInset:UIEdgeInsetsZero];
}

// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
    //[cell setPreservesSuperviewLayoutMargins:NO];
}

// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
    //[cell setLayoutMargins:UIEdgeInsetsZero];
}

我当前的代码如下所示

- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

-(double) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 3) {
        return 700.0;
    }
    return 44.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 3) {
        static NSString *homeTableIdentifier = @"GeneralInfoTableViewCell";

        GeneralInfoTableViewCell *cell = (GeneralInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:homeTableIdentifier];
        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"GeneralInfoTableViewCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else if (indexPath.row == 2) {
...

请注意,我删除了在此视图中显示两次的徽标,这就是为什么“erbjudanden”在下面的错误视图中被截断的原因。

这是 iPhone 4s 模拟器中的视图(正确方式)。

这是实际 iPhone 4s 上的视图(错误方式)

我能做些什么来解决这个问题?

【问题讨论】:

  • 我认为这是单元格的高度问题。你需要增加高度
  • 你的设备和模拟器的ios版本是多少?
  • @Misha 你能解释一下这有什么帮助吗?我是否应该增加单元格的高度或在 heightForRowAtIndexPath 中返回的数字?除一个为 700 的单元格外,所有单元格的高度均为 44。这些是自定义且非常基本的表格视图单元格,其高度定义为 44,但一个为 700 的单元格除外。谢谢!
  • @EICaptain 设备为 8.1,模拟器显示相同的 8.1、8.2 和 8.4。模拟器截图来自 8.4。
  • 我认为您已将 Cell 和 contentView 的 backgroundColor 设置为 UIColor ClearColor 这就是文本显示在分隔符下方的原因,否则它将被截断。

标签: ios objective-c iphone uitableview


【解决方案1】:

我的设备运行的是 iOS 10,而我的模拟器运行的是 iOS 9.3。

我怀疑视图层级调用发生的顺序略有不同,导致两者的显示不同。

在更新所需视图之前致电view.layoutIfNeeded() 帮助了我。

【讨论】:

    猜你喜欢
    • 2019-09-24
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多