I want to implement pull to refresh effect but on UITableView bottom using UIRefreshControl ?
Any ideas?
It is not possible to put UIRefreshControll to bottom of UITableView in a manner similar to putting it to top. But anyway, you're able to place everything on table view's background view.
But the solution which I prefer is to download additional items when user scrolls to the most bottom of table view. I handle it via UITableViewControllerDelegate method:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == self.items.count - 1 {
// Download more items
}
}
These are the two things i typically do:
Configure a Footer View which displays the loading Indicator.
Provide a additional cell from the TableViews or CollectionViews
Datasource which presents a loading indicator. Depending on the current loading state it could display a label like "No more items available" or the actual Indicator
Related
Hy Stack family
I am facing the issue. I put tableview in scroll view with some other subviews. I am making an food ordering app. In which when i scroll up so my collection view will automatically scroll according to my tableview section or either i just select my category from collection view and i want to scroll my tableview at that position so my app user will select that product to order.
Plz help me out how can i handle tableview delegate methods when my main scrollview scrolling!
func tableView(_ tableView: UITableView,
willDisplay cell: UITableViewCell,
forRowAt indexPath: IndexPath) {}
This method is not working for me when i do scrolling!
1.check your delegate img 1 img 2 img 3
check your numberRows DataSource return count values (count !=0 )
check height of cell
In my iOS app, I do have my UIScrollView that contains UITableView with classes (cells) containing UIImages.
Now I do need to update the UIImages programmatically.
However the visible part of my UIScrollView does not update, unless I do scroll the changed item (UIImage) off the visible screen and back.
I've tried setNeedsLayout, setNeedsDidsplay for my UIScrollView, UITableView -- no success.
Any idea on what I could do wrong, or how can I force the ScrollView to update without actual scrolling?
Solved.
At first, UITableView inside UIScrollView was unnecessary since UITableView scrolls itself.
The solution was to use ReloadData method for my TableView.
this is because tableView calls func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell when cell reappear on screen so that it can reuse cell object to save memory, so call tableView.reloadData() or func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation) whenever ( after data is changed obviously ) you want to reload the entire tableView or particular cell respectively.
And no need to use scrollView for tableView since tableView inherits from scrollView.
i have table view inside table view cell, need to set table view height depending on table view content, i tried below code
extension tableViewCell: UITableViewDelegate{
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
lcOptionsTVHeight.constant = tableView.contentSize.height
}
}
}
but this is not working in first load, but updating as i do scroll up and down, how can do load in properly in first load itself?
heightForRowAt(:)
You need to pass your height in heightForRowAt(:)
In this method, you need to check if it's the nested tableview cell and return the height, in other cases just return UITableView.automaticDimension
My suggestion would be to use sections instead of nested tableview. Only if there's horizontal scrolling requirement(not the case here as you mentioned tableview inside a tableview cell), we can go with a collectionview inside tableview cell.
Here, using different sections might be sufficient. You can reload sections by tableView.reloadSections
Again it might be dependent on your requirement. In general, we don't see tableview inside a tableview cell.
I'm working with some legacy code and it looks like they added a custom sticky header view in the viewDidLoad. The issues is that I need to add the sticky header view AFTER the other cells are returned so that I may send the sticky header view to the back of the other cells so it can be used as a background for the topmost cell.
like so:
homeScreenTableView.sendSubviewToBack(headerView)
or
homeScreenTableView.insertSubview(headerView, at: 0)
The issue is there is no call back after the cells are returned in a tableView. I know this is a bit hacky, but is there a way to do this?
You check if the last indexPath in indexPathsForVisibleRows array has been displayed on screen.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let lastVisibleIndexPath = tableView.indexPathsForVisibleRows?.last {
if indexPath == lastVisibleIndexPath {
// finished loading
}
}
}
I need to add a table view in a specific are of my screen which is inside another UIView. When the user press a button the table view is created and displayed perfectly fine. However I need to know the user selection so I create it in the following way:
self.dynamicTableView = UITableView(frame: self.viewForTableView.bounds)
self.dynamicTableView?.dataSource = self
self.dynamicTableView?.delegate = self
self.messageZone.addSubview(self.dynamicTableView!)
self.dynamicTableView?.reloadData()
The data sources methods are being called but the delegate is not, so the following println is not working
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("Hello")
}
As additional information I'm using a custom table view cell
UPDATE: I just discover that if I implement shouldHighlightRowAtIndexPath sometimes if I do a long press it works, like if I keep the cell pressed for about four seconds, but not always, just some times. Can it be any view that is behind the table view what is causing this weird behaviour?