简体   繁体   English

Xcode 9 Tableview调整大小错误

[英]Xcode 9 Tableview resizing error

I am really bummed because I just released this app to the App Store, and now that I have updated to Xcode 9, a tableview I had is now having problems. 我真的很高兴,因为我刚刚将此应用发布到App Store,现在我已更新到Xcode 9,现在我遇到的表格视图出现了问题。 The old tableview, in iOS 10, places the cell around 100 coordinates below the top of the tableview, so I was able to add labels and stuff above the tableview, with the cells starting out below them, but then able to be scrolled under them. 在iOS 10中,旧的表格视图将单元格放置在表格视图顶部下方约100个坐标处,因此我能够在表格视图上方添加标签和内容,单元格从其下方开始,但随后可以在其下方滚动。 But now when I run the app on an ios11 simulator, it gets rid of the tableview header, but when I run it on my own phone, it does not. 但是现在,当我在ios11模拟器上运行该应用程序时,它摆脱了tableview标头,但是当我在自己的手机上运行该应用程序时,它却没有。 I have not set any code determining the header of the tableview, and this is my current code: 我没有设置任何代码来确定tableview的标题,这是我当前的代码:

  myTableView.frame = CGRect(x: 0, y: 110, width: self.view.frame.width, height: self.view.frame.height - 140)

and is a photo to help visualize it: https://imgur.com/a/I4iMo 并且是一张有助于形象化的照片: https//imgur.com/a/I4iMo

I need to get the tableview to be equal to the tableview in the iPhone 6s rather than the simulator 我需要使表视图等于iPhone 6s中的表视图,而不是模拟器

Try putting that exact line of code inside viewDidLayoutSubviews . 尝试将确切的代码行放入viewDidLayoutSubviews

Put this in your ViewController. 将其放在您的ViewController中。

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    myTableView.frame = CGRect(x: 0, y: 110, width: self.view.frame.width, height: self.view.frame.height - 140)
}

It is very poor coding to deal with constant sizes like you do. 像您一样处理恒定大小的代码非常糟糕。 You should rather create a tableHeader, or constraint a UIView above the tableView - where the height of this UIView is based on the size of its content. 您应该创建一个tableHeader,或者在tableView上方约束一个UIView该UIView的高度取决于其内容的大小。 In your code, what happens if the user turns on bigger fonts in Accessibility? 在您的代码中,如果用户在“辅助功能”中打开较大的字体会怎样? The text might grow outside your 100pt view.. 文字可能会超出您的100pt视图范围。

If my code doesn't work, try using some of the new safeArea-variables, eg: 如果我的代码不起作用,请尝试使用一些新的safeArea变量,例如:

myTableView.frame = CGRect(x: 0, y: 110+self.view.safeAreaInsets.top, width: self.view.frame.width, height: self.view.frame.height - 140)

Play around with the safeAreaInsets until you understand what they do. 一直使用safeAreaInsets直到您了解它们的作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM