【问题标题】:UITableView works in iOS 7 but appears crushed in iOS 8UITableView 在 iOS 7 中工作,但在 iOS 8 中看起来很糟糕
【发布时间】:2014-08-31 23:32:10
【问题描述】:

这里还是 iOS 编程新手。拥有一个在 iOS 7 上完美运行但在 iOS 8 中看起来很糟糕的 UITableView。多个设备。在使用模拟器(iOS 7 与 iOS 8 模拟器)时也会出现相同的问题/差异。

我正在使用 Xcode 6 beta 6、Yosemite beta 6、iOS 7.12 和 iOS 8 beta 5。

我已经让代码尽可能简单和完整以显示问题:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.
        return [self.numberOfDays count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];

        NSLog (@"%li", (long)indexPath.row);

        UILabel *label;
        label = (UILabel *)[cell viewWithTag:1];
        label.text = @"Monday";

        return cell;
    }

注意我的 NSLog 语句。我的 UIViewTable (0-87) 中有 88 行。

  • 当此表在 iOS 7 中加载时...

    • 我的控制台中有 12 行
    • 这就是初始可见行数
    • 表格滚动流畅...一切都很好。
  • 当此表在 iOS 8 中加载时...

    • 我的控制台中有 88 行代码
    • 这对我来说没有意义
    • 表格的初始外观看起来不错
    • 例如前 12 行显示正确
    • 表格滚动不正确。
    • 第 12-87 行的高度约为 1 像素。

表格的初始外观看起来不错(例如,前 12 行显示正确),直到我尝试滚动它。然后第 12-87 行出现大约 1 个像素高。

请帮忙!

好的 - 就像添加一样简单: tableView.rowHeight = 44; 在我的静态 NSString *CellIdentifier = @"Cell";线。 我不需要这是 iOS 7,不知道为什么我在 iOS 8 中需要它。

【问题讨论】:

    标签: uitableview ios7 ios8 xcode6-beta6


    【解决方案1】:

    好的 - 就像添加一样简单:

        tableView.rowHeight = 44; 
    

    在我之后

        static NSString *CellIdentifier = @"Cell"; 
    

    线。我不需要这是 iOS 7,不知道为什么我在 iOS 8 中需要它。

    【讨论】:

      【解决方案2】:

      您的解决方案可能有效,但最好实现 heightForRowAtIndexPath 方法

      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
      {
            return 44;
      }
      

      我不知道为什么 iOS 7 和 8 之间存在差异,也许其他人可以对此有所了解?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多