start position of table view is wrong in simulator

2020-02-06 16:53发布

问题:

I created a tableview in storyboard, which looks good, but the start position is wrong in the simulator or device. The 'Label' should not be at the same position as the time. How could I solve it??

回答1:

Simulated metrics are just that. Simulated. They're useful to set to how the view will actually display in order to help set up the look in the storyboard, but whether or not a navbar or tabbar shows up in the actual program is irrelevant to whether or not you've selected it as a simulated metric on the storyboard.

In this case, you're probably using constraints, and setting the label's y origin to be 0 pixels below the container view. When you use the simulated storyboard metrics, this puts the label just below the navbar that you're simulating on the storyboard. But in your actual project, you've done nothing to include a navbar on this scene, and your label is appearing at the top of the view controller.

You can either learn how to prevent the status bar from displaying... or you can move the label's y origin to being a 20 pixels down (the height of the status bar).


I can provide more help if you provide more details on how you're doing your layout (autolayout?), and exactly how you want it to look. But I'd start by leaving ALL of the simulated metrics on inferred and only ever explicitly change a simulated metric after you've written the code to programmatically add/remove one of the features you can change via the simulated metrics.


If you take nothing else away from this answer, please understand this: Selecting an item from a simulated metrics dropdown menu only changes how the view appears in the storyboard and doesn't change what will actually display in your app.



回答2:

try this

self.edgesForExtendedLayout = UIRectEdgeNone;

hope this will help you.