I'm attempting to display a static tableview in my UITableViewController as I only want to display 1 row. I've set the tableview's content to Static Cells already but I still get more rows than I want to appear when I deploy it to my test device. I've also explicitly set the number of rows and sections in my UITableViewController subclass but still the results are the same.
I've attached some screenshots to further explain the result I'm getting.
Here's a screenshot of what my tableview controller looks like in the storyboard
Here's a screenshot of the attribute inspector of my table view
Here's a screenshot of my UITableViewController subclass
Finally, here's a screenshot of what the tableview looks like on the test device
As you can see even though I set the number of static rows to 1, I still get multiple rows. I'm not sure why this is happening but if anyone has any ideas, I'd appreciate the help.
Thanks
Change the table view's style to Grouped.
This should give the effect you desire:
An alternative to .grouped style, if you have to use .plain, is to attach a zero height tableFooterView to the table view since it won't draw separators below a footer.
You can either drag a view into the table view in Interface Builder, or add it in your viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
Related
I need 5 viewController all of them has the same header components. So I don't want to duplicate the same views and codes for each viewController. I would like to create a header and use the header for each viewController.
The problem is header will be filled by an object and this object has a list attribute. so i need to add this list attribute such a tableView.
What one view controller look like
I am trying to create an headerViewController and pass my object to it. And i will use this viewController in a container view for each 5 main view Controllers. But the height would be different so I can't define a height constraint to container view. in 5 view controller should use scroll view, because the total height will be higher than screen.
It is a little bit complicated because i try to solve this problem such a android developer :)
Assuming you want all items in tableView to be displayed all the time (no scrolling in tableView)
You should add height constraint to tableView or containerView
After loading/reloading the tableView with data set tableViewHeightConstraint OR containerViewHeightConstraint with content size height of tableView
tableViewHeightConstraint.constant = tableView.contentSize.height
OR
containerViewHeightConstraint.constant = tableView.contentSize.height
I have solved this issue creating a main view controller that contains a table view. And the common header is a type of tableviewcell. Then for each different body parts became another tableviewcell so according to type attribute of viewCOntroller, I am loading related tableviewCell.
I did this after #midhun-mp comment. Thanks to him.
I dragged a tableView to my controller in storyboard. I set the type to grouped, but I don't know if I can set the tableView's section number in storyboard.
I can not see the tableview's content to Static Cells. If I do this it will report error.
You cannot do that in tableView because it does not support static cells.
However if you use TableViewController
you can create static cells and you can create your desired sections and as well as add section number too.
Table View controller gives a more flexibility than Table View alone.
I attempted to use UITableView (with static content) to create a setting screen similar to the iPhone's system setting screen. It mostly works excepts the blank space under the last row are filled with white row cells instead of background color, as shown in this screenshot:
I have tried various ways to fix this: setting the table view's background, add an empty row as the last row with the background color. What should be the right fix?
Objective-C
[[UITableView alloc] initWithStyle: UITableViewStyleGrouped]
Swift 2
UITableView(style: .Grouped)
Swift 3
UITableView(style: .grouped)
You should also be able to set the table view style in the interface builder.
You need:
tableView.tableFooterView = UIView()
How to remove empty cells in UITableView?
Eliminate extra separators below UITableView
Go to View Section of the TableView's Attributes Inspector and set the background color there. It will work
I'm building my application with Swift and I want to set up TableView and CollectionView in the same ViewController.
The only answer I founded is to setup my CollectionView in the TableViewCell of the TableView.
I did it but it scrolls separately.
The solution I found is to disable CollectionView scrolling and then configure CollectionView's height constraint programmatically by summing heights of the cells. It isn't perfect at all because cells become non reusable (250+).
I'm in desperation because I have seen this setup in many other apps and I think that answer is so simple but I can not find it anywhere.
Can anyone please help me? Thank you a lot!
Another option is to set it up as a single collection view with two sections, one that looks and lays out as a tableview and the other that has the more collection view appearance.
Or set it up as a single table view with two sections, one of which displays two side-by-side images per line (this is the old school way of creating this layout.)
Lots of ways to go about it, depending on what you want to play with and what you want to learn :)
You can put a UITableView and UICollectionView inside a UIViewController, and implement UITableViewDelegate, UITableViewDataSource and UICollectionViewDataSource.
Keys:
Use AutoLayout to make sure tableView has only two rows, and
collectionView takes the rest of area.
Make sure tableView.scrollEnabled = false
Here is a sample, https://www.dropbox.com/s/v6yc40udfk8mqx5/FlexTableCellHeight.zip?dl=0
Set up a blank ViewController. Then place two ContainmentViewControllers inside of the ViewController. Size them however you want based on how much screen you want to the be tableview and how much you want to be collectionview. Then create segues from each containmentViewController to your tableviewcontroller and collectionviewcontroller using embed. This will allow both to be on screen at once and scroll separately.
If you do not need to use a TableViewController and can get away with just a tableview you can also just place one containmentviewcontroller below your tableview and create the embed segue to your collectionviewcontroller.
i found this guide for make grouped table view with iOS6 style:
ios7 grouped rounded tableview but if i apply this code in UITableViewController i have a wrong lateral margins to view for my cells.
i need use UiTableViewController instead of UiViewController with TableView for using refresh table, for automatic scroll cell with textfield when keyboard appears and more...
any idea?
this is my result:
but I would like to get this:
Why not embed your UITableViewController into another UIViewController, as a child view controller?
You will be able to easily change the margins of your container view.