As shown in the [figure]
when I scroll down to the end appears a large block with nothing, How to remove this and scroll the scroll only until the end of UiTableView content?
the following images describe the configuration of my uitableview in the storyboard:storyboar_one, storyboard_two, storyboard_three
this my viewDidLoad Method:
override func viewDidLoad() {
super.viewDidLoad();
tableView.dataSource = self
tableView.delegate = self
let nib: UINib = UINib(nibName: "ObrigacaoTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "reuseIdentifier")
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 150
}
Try self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for therefore it shows up as a blank space.
Also make sure the bottom edge inset of UITableView is 0
To remove blank cells in the table keep the below code in viewDidLoad() method after estimatedHeight,
tableView.tableFooterView = UIView(frame: .zero)
Remove empty cells in UITableView
self.tableView.tableFooterView = UIView()
I had created this.
.
please ignore the blur part which is the problem of creating .gif.
I did this using autolayouts.
my code is :
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.estimatedRowHeight = 100
self.tableView.rowHeight = UITableViewAutomaticDimension
}
for toggling action of Remarks button which is written in custom cell class:
#IBAction func toggleAction(_ sender: Any) {
if(hc.constant == 75){
hc.constant = 0
}
else{
hc.constant = 75
}
}
where hc is height constraint of textview. What my doubt is that can the tableviewcell will re-size after toggling the below textview? If yes, How?
All suggestions are welcome. Thanks.
After changing constant you have to call either cell.contentView.layoutIfNeeded() if change before return cell or tableView.beginUpdate() follow up by tableView.endUpdate() to update the table view height
You already using UITableViewAutomaticDimension so it should be update automatically with the constraint
SubViewController (a child of ViewController and IndicatorInfoProvider) is added using MainViewController (a child of ButtonBarPagerTabStripViewController) with NavigationBar added.
Padding does not occur even if you tap tabbutton, padding occurs on top when swipe.
animated gif 👇
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.clear
//tableview
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.backgroundView = nil
self.tableView.backgroundColor = UIColor.clear
//動的に高さを変更
self.tableView.estimatedRowHeight = 155
self.tableView.rowHeight = UITableViewAutomaticDimension
//indicator
self.tableView.showIndicator()
//loaddata
loadData(page:0)
}
I've encountered the same problem.
Open your storyboard and select the MainViewController. In the Attribute Inspector deselect the checkbox 'Adjust scroll view insets'
Are you using a UITableViewController as a childViewController? This issue seems to happen in this case.
To fix this, you should be setting automaticallyAdjustsScrollViewInsets = false and also having as childViewControllers only UIViewControllers with a UITableView inside, instead of UITableViewController.
Cheers
I've created an UITableView with UITableViewCell. Between the view cells there are grew lines. I want to delete these lines and don't want to show them, but I don't know how.
I work with Xcode 6.1 and Swift.
Here is a screenshot that displays my screen:
THX!
Using Objective-C, we have:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
for Swift 3:
self.tableView.separatorStyle = .none
for Swift 2:
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
OR:
if you are using the InterfaceBuilder, you can set the tableView's Separator property to None
Within InterfaceBuilder you can set the Separator property to None or do it programmatically by setting the property separatorStyle of your table view to UITableViewCellSeparatorStyleNone.
Swift 3:
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
You can do it from storyboard like this;
Swift 5 Programmatically
private func buildTableView() -> UITableView {
let tableView = UITableView()
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.separatorStyle = .none
return tableView
}
Swift 5 :
cell.selectionStyle = UITableViewCell.SelectionStyle.none
tableView.separatorStyle = .none
when initializing the tableview. It can be set or through the storyboard or nib
If you are setting up a lazy tableView, you may want to change the color to clear, seems like an Apple bug where sometimes the style is replaced on layout cycles.
private lazy var tableView: UITableView = {
let table = UITableView(frame: self.view.bounds, style: .insetGrouped)
table.separatorStyle = .none // <- HERE
table.separatorColor = .clear // <- HERE
table.delegate = self
table.dataSource = self
table.estimatedRowHeight = UITableView.automaticDimension
table.register(UITableView.self, forCellReuseIdentifier: "MyCell")
return table
}()
I have a UITableViewController subclass with sections. The sections are showing with the default style (no rounded corners). How can I set the TableView style to grouped in the code? I'm not using Interface Builder for this, so I need something like
[self.tableView setGroupedStyle]
I searched on Stack Overflow, but couldn't come up with an answer.
You can do the following:
UITableView *myTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
Swift 3:
let tableView = UITableView.init(frame: CGRect.zero, style: .grouped)
If i understand what you mean, you have to initialize your controller with that style. Something like:
myTVContoller = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
I give you my solution, I am working in "XIB mode", here the code of a subclass of a UITableViewController :
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithStyle:UITableViewStyleGrouped];
return self;
}
Below code Worked for me, I am also using UITableview class
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
}
return self;
}
If you are inheriting UITableViewController, you can just init tableView again.
Objective C:
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
Swift:
self.tableView = UITableView(frame: CGRect.zero, style: .grouped)
Setting that is not that hard as mentioned in the question. Actually it's pretty simple. Try this on storyboard.
Swift 4+:
let myTableViewController = UITableViewController(style: .grouped)
Swift 4
Using Normal TableView
let tableView = TableView(frame: .zero, style: .grouped)
Using TPKeyboardAvoidingTableView
let tableView = TPKeyboardAvoidingTableView(frame: .zero, style: .grouped)
If you create your UITableView in code, you can do the following:
class SettingsVC: UITableViewController {
init() {
if #available(iOS 13.0, *) {
super.init(style: .insetGrouped)
} else {
super.init(nibName: nil, bundle: nil)
}
}
#available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
For set grouped style in ui itself:-Select the TableView then change the "style"(in attribute inspector)) from plain to Grouped.
You can also do this if you want to use it on a subclass you've already created in a separate swift file (probably not 100% correct but works)
override init(style: UITableViewStyle) {
super.init(style: style)
UITableViewStyle.Grouped
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Now in you appdelegate.swift you can call:
let settingsController = SettingsViewController(style: .Grouped)
You can do this with using storyboard/XIB also
Go To storyboard -> Select your viewController -> Select your table
Select the "Style" property in interface-builder
Select the "Grouped"
Done
If you have one TableView for more tables, and one of this tables is grouped and the another one plain, than you can simulate the plain style with the function from UITableViewDelegate:
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.min
}
swift 4
if you don't want use storyboard, this might be help.
you can add table view and set properties in a closure:
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.backgroundColor = UIColor(named: Palette.secondaryLight.rawValue)
tableView.rowHeight = 68
tableView.separatorStyle = .none
tableView.translatesAutoresizingMaskIntoConstraints = false
return tableView
}()
then add in subview and set constraints.
If you're not using Storyboards and just want a clean, concise way to setup your UITableViewController subclass to use a different tableView style, you can simply override loadView like this:
override func loadView() {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.delegate = self
tableView.dataSource = self
view = tableView
}
As the documentation says:
loadView creates the view that the controller manages
it's a method you can ovveride when using ViewControllers whose views are not defined via Storyboards or NIBs.
The UITableViewController implementation already overrides this method for you to crate a simple, plain UITableView as the root view for the controller, but nothing stops you from further overriding it to create a table view that better suits your needs.
Just remember:
Your custom implementation of this method should not call super.
You can also try to make the separator line color clear which could give the grouped style effect:
[myTVContoller.tableView setSeparatorColor:[UIColor clearColor]];
You can use:
(instancetype)init {
return [[YourSubclassOfTableView alloc] initWithStyle:UITableViewStyleGrouped];
}
self.tableView.style = UITableViewStyleGrouped
EDIT:
Had assumed this was a read/write property. In that case, you can either follow Dimitris advice and set the style when you instantiate the controller, or (if you're using a XIB), you can set it via IB.