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
Related
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
}
}
}
The problem here is I want the UITableViewCell to fully take the view of the cell and once I swipe down the other cell has to appear. What I have here is the other cell also appears on the same UITable screen. As you can see the title of the other news also can be seen in the UITableView. I want the first data to cover up the entire screen and once I swipe down the next data(title,image,description) has to be added.
In viewDidLoad(), make paging enabled:
myTableView.isPagingEnabled = true
then assign height to your cells,
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.myTableView.frame.size.height
}
I have UITableView in UIViewController in this view controller total 3 tableview or 2 UICollectionView. so in this one tableview contain many cells or cells data are not static its dynamic according to server. So, I create the table view height outlet & its set on cellforrowatindex function of tableview.
So, we use to set height tableview_height.constant=tableview_height.constant+cell.frame.size.height using this code my problem showing whitespace on the end of UITableViewCell. If I increase the cell then cell are cut from the bottom. I am giving below constraint show in the pic.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if indexPath.row == 0
{
tableview_height.constant = 0
tableview_height.constant=tableview_height.constant+cell.frame.size.height
}
else
{
tableview_height.constant=tableview_height.constant+cell.frame.size.height
}
return cell
}
Check my answer on the almost same question.
How to increase the height of parent view according to height of UITableView in swift?
It is the best way to achieve what you want, because it does not depend on your table settings or if you have header/footer/custom insets/whatever.
Hope it will help.
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