UITableView dosen't change the size of UIScrollView when adding Cells - ios

The scrollView, which is there with UITableView dose not change it's size.
So I have a UITableView, where Cells are added by the User. Right after adding these cells, I'm calling
[self.tableView reloadData];
Now the tableView shows the new cells added by the User. fine. But, if the tableView get's larger, if it's too big to show everything in the view, it doesen't change the size of my scrollView. I have no scrollView in the view, aside from the "normal" scrollView, which comes with the UITableView. So I can't scroll to the last row, because the scrollView is "too small".
Is there anything I forgot? I'm thinking of something like
[self.tableView.scrollView reload];
I'm using the same concept in another class: The user is able to add cells and they're shown. But in the other class the scrollView "resizes" correctly.

I assume that you have table inside a scrollview. You need to change content size of scrollview after adding cells. Height of content size should change according to content in scrollview so that you can scroll through whole content.
Updated answer:
I think your tableview's frame is larger. It is crossing window's bounds. Try minimizing tableview's height.

Related

Add tableview to scrollview and have scrollview keep growing in height as cells are added to tableview

I want to make a full screen scrollview with various views in it but also have a tableview in it.
The thing is, I don't want the tableview to "reuse" views.
I am using auto-layout.
People keep asking why. Here is why:
I want the scrollview to keep growing in height as cells are added to the tableview. (using storyboard) This is something I want to do. Stop "suggesting" a "better" way because I know the "better" way. I am asking for this way.
For example:
As cells are added to the tableview, the entire scrollview keeps growing.
Hope you are using autolayout, considering this i guess you already added constraint from the bottom of tableview to the uiview below it and also add a height constraint to the tableview. Make a IBOutlet of this height constraint. now write a method that would calculate the height depending on number of items you have to show for the tableview like
func calculateTableViewHeight() {
heightConstraint.constant = YOUR_CELL_HEIGHT * NO_OF_ROWS
}
Call this method after tableview.reloadData(). And also don't for get to set the scrolling for the tableview to false

UITableView Footer is not showing

enter image description here The Controller is UIViewController.
I have a UIScrollView in UIViewController. A Tableview is added as a subview upon the scrollview. The Scroll view content size is bigger than the screen size. There is a footer in the Tableview. When I am reloading the Tableview first time with the data then the Footer is not displaying but when I started the scroll then the footer is not displaying properly.
Could you please guide me, how to make this resolve.
Thanks
Firstly, it's wrong practise to add UItableview inside scrollview, because tableview already has scrollview underneath it and will adjust the content size of tableview automatically depending on the content you add.
Can you please let me know the reason why you have added tableview inside scrollview?
Remove tableview from scorllview and everything show work fine.

UITableView inside UIScrollView - Cell not clickable

I have a problem with a UITableView not detecting touches.
In an iPhone-only app, I have a UIViewController, which containts:
UIScrollView
UIView (let's say a content view)
Some labels
UITableView (last)
The labels have a dynamic height, because they contain some text that I must retrive from the web, so I'm using auto layout.
I'm setting the content size of the UIScrollView inside the viewDidLayoutSubviews method, and I'm doing this by summing UITableView.frame.origin.y and its height.
Here comes the problem: when the labels contain only some words and the UITableView does not exceed the iPhone screen size, everything works ok. But when they grow, and the UITableView gets pushed down, when I scroll down I can't click on the cell anymore. Also, if when loading the view the table is half visible and half not, I can click the visible cells, but if I scroll down, I can't click the others.
I'm using swift 2 and Xcode 7.
Here is an example:
Clickable:
Unclickable:
Do the following thing:
yourView.clipToBounds = true
Now, if UITableView does not appears means your UIView is not same bigger to hold down UITableView.
Make sure that your UIView height is bigger to hold the contents in it and then try to tap on it.
Updated:
If you are using AutoLayout, then do the following thing.
Give the fix height to UIView
Take the outlet of height constraint of UIView
Now, in viewDidLayoutSubviews change the constraint of UIView to UITableView contentSize height.
self.heightConstraint = self.tableView.contentSize.height
Let me know, if this helps!
Adding some info to the #Rémy Virin's answer here:
From Apple Documentation, you shouldn't embed a UITableViewinside a UIScrollView.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Addition:Solution Since you want to scroll the content above table also, the one solution is place a Header View for the Table and place the Content over there to make it Scroll along the Table View.
If you use Autolayout, no need to specify contentSize to UIScrollView as it will automatically expand by taking the height of its subview.
In your case, increase the height of the Base UIView (content view as mentioned by you) which holds the tableView when the tableView height increases.
UITableView becomes unresponsive when it extends below its container view.

UITableView didSelect delegate doesnt gets called?

In my app, I have added an UITableView over a ScrollView. I have disabled scrolling in table view.
So, only the scrollView Scrolls, I have adjusted the scroll view content Size with the tableView Frame. So, I can access all the cells.
Consider, there are 5 rows visible in the screen, if I tap any of the row, the didSelectRowAtIndexPath method gets called. If I scroll down, say to 6th cell and tap on it. The method doesnt gets called.
Same issues happens with UIcollectionView.
The reason why I have added so is. When I scroll the Scroll View, a view in that should get fixed in the top and the tableView behind it should go on scrolling. You might have seen in many of the apps in Android. So, I have used the ScrollView didScroll delegate to get the offset position. As per it, I will make the view to be fixed and vice versa.
Make the height of UITableView same as the content height of table.
Then set the content size of UIScrollView as the height of UITableView
Here is a brief example to demonstrate
CGRect rect = tblTopics.frame;
rect.size.height = tblTopics.contentSize.height;
tblTopics.frame = rect;
self.scrlVwFacultyDtl.contentSize = CGSizeMake(self.scrlVwFacultyDtl.frame.size.width, tblTopics.frame.size.height);
In the above example the tblTopics is the instance of UITableView and scrlVwFacultyDtl is the instance of UIScrollView
hope it will help you..

UICollectionView with custom UICollectionViewLayOut

I am trying to have the content in a uicollectionviewcell grow bigger when it scroll moving in one direction. i initially set the size of the cell to the largest size i want, then the content inside the cell is half in terms of the size. the content is an uiimageview.
So I have a custom UICollectionViewFlowLayout in which I subclassed the layoutAttributesForElementsInRect to make the uiimageview in the cells grow bigger when it is moving in one direction. i also have shouldInvalidateLayoutForBoundsChange to return YES
Everything works perfectly when i scroll, the imageview will grow larger. However if i select a cell to push to a new viewcontroller, and then when i click the back button to come back to this uicolletionview, the enlarged uiimageview in severals cells are showing in the original size. They can only go back to the correct enlarged size if i scroll again, why is that? and how can i make it keep its enlarged size after getting pushed?
i tried invalidatelayout but it will just refresh the layoutattributes with correct enlarged size of the content, but the view is just not updated eventhough the size is already enlarged.
thanks
I had a similar issue when designing cv cells and would gess the issue is with when the subviews get calls to update their size, which might not happen when the view refreshes.
Instead of resizing content in the cell, you might want to dynamically size the cells themselves and have the content automatically adjust to that size. Calling [mycollection invalidateLayout] then should be all you need, maybe not even that.
The method is
collectionView:layout:sizeForItemAtIndexPath:
which you declare in your UICollectionViewFlowLayout.h
If you then run into trouble where subviews do not resize with cell size, related problems can arise from constraints/autolayout etc of the subviews.

Resources