user3142972
user3142972

Reputation: 897

UITableViewController UI issues in swift

I'm using Parse to set up a log in system for my app. When the user logs in, they're taken to a TableViewController with different options to choose from. For some reason, the TableView comes all the way up through the status bar, and it doesn't look good. Also, in my code is set the TableView's title, but that title doesn't show up. Here are the properties of the TableViewController.

And here's the status bar, where the title should be.

How do I fix the problem?

Upvotes: 1

Views: 395

Answers (2)

li_shengdm
li_shengdm

Reputation: 43

I think you should set the tableview some constraints.

To make this clear, I make a small project containing just one viewController, which has a tableview as its subview. After that, I attach the tableView some constraints By the follow steps:

1.select the tableview in the storyboard;
2.click Editor->Pin in the menu;
3.select "leading space to superview","trail space to superview","top space to superview","bottom space to superview"
4.open the utility area and select "Show the Size inspector". Edit the constraints to make sure the value of "top space to superview" equals to 20(because 20points is the heigh of the status bar), while the the other three constraints' value equal to 0.
After doing these, you will create a tableview which lies 20point under the status bar.

I think posting some images would be much better, but I'm new to stackflow, so I haven't gain enough reputation to post a image, sorry for that.

Upvotes: 1

Acey
Acey

Reputation: 8098

It sounds like you would like to have a UINavigationBar atop your view. That's easy to do!

Wherever you are present/displaying your TableViewController (maybe it looks like this now)

MYTableViewController *vc = [[MYTableViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:vc];

instead do the following: (Making up a class name here)

MYTableViewController *vc = [[MYTableViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:navController];

OR if you are using Storyboards to present your VC (it looks like you are using a storyboard for some parts at least)

Just drag on a Navigation Controller object and reroute the ViewController it brings out with

Oh yeah and the 'Title' property is for UITabBarController containers mostly. When you get this set up with a navigation controller, you will be able to set the title of that by setting

self.navigationItem.title = @"Test"

or in the Nib by selecting the newly appeared navigation bar and changing the title property; you'll see it if you went with the nib approach.

Upvotes: 1

Related Questions