scroll table view inside UIScrollView in storyboard ios - iphone

I always face problems with the UIScrollView which is:
I have a UIViewController that contains two tableViewControllers, the contents of these tables are bigger than the height of the iphone, so I need to use a scroller. I enable the scroll of the table, but the height of the table is big, so I need to scroll all the screen also, for this reason, I added a UIScrollView and I put these two tables inside, for now I have three scrolls, (for the two tables and for the UIScrollView).
What I need is: to allow scroll the tables with the scroll of whole screen, it means to combine the scroll of the table with the scroll of the UIScrollView.
Is there any method to combine the scrollers??

you dont need to put a UIScrollView behind the UiTableViews as the tableViews have their own scrollers. No matter how much data/cells you have in the tableView it will allow you to scroll easily.

Related

Multiple regular vertical tableviews inside of one horizontal collectionview

Hello I am trying to display multiple vertical table views inside of ONE horizontal view on iOS. Is this possible? The table views themselves should be able to scroll vertically like normal but I should also be able to scroll horizontally between multiple tableviews, all in the same viewcontroller (if possible). I have attached an image of what it should look like . As you can see, I should be able to scroll the tableviews vertically independently from the horizontal scrolling that is used to display different tableviews. All while keeping the header visible (Engineering, Scholarships, etc.
What strategy should be done on iOS/Swift, is there a tutorial? I am OK with using a UICollectionView instead or any other type of view. Thanks so much!

how to set the content size of a scrollView Dynamically

I have a scrollView and on that scrollView, i have many labels and textView along with one tableView. scrollView is working perfectly fine when the no. of rows are less in tablView but if tableView have more number of rows then i am not able to full content and even i am loosing lots of information in tableView because the tableView isn't scrollable. i have added all the lables, textView and tableView as a subview of scrollview. Can anyone help me in that so i can get full tableView and make it proper scrollable.
Here is my code to set the content size of scrollView.
float maxHeight = 0;
for(UIView *v in [self.scrollView subviews]){
if(v.frame.origin.x + v.frame.size.height > maxHeight)
maxHeight = v.frame.origin.x + v.frame.size.height;
}
self.scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, maxHeight+100);
First you'll need to resize your table, so that it fits all the rows (since as you said, it's not scrollable). I believe that doing so will make all your rows to not be reusable, so if it's a big table you may get performance issues. Also be aware of #David H's answer, so if you really want to do this, you might be better of using another UIScrollView instead of the UITableView (it won't bring much benefit either way).
Second, you'll need to move all the views beneath the tableview, so that they won't overlap. An easy way to do this is to have those views put together in a different view, so that you only need to move one view instead (in this case however, you'll also need to resize that view accordingly).
Finally, instead of looping through all the scrollview's subviews, it should be easy enough to keep track of the view that is closest to the bottom (this depends on how you generate and add the views to the scroll view).
A tableview is a scroll view subclass, and generally Apple says adding it to another scroll view will cause problems. That said there are ways to make it work. Search here or on google for terms like "how to put a uitableview in a uiscrollview".
EDIT: to make it not scrollable you could put a transparent view over the table view that stops or eats touch events.
self.scrollingView.contentSize=CGSizeMake(320,372);
Try this.

How to implement smooth scrolling using both a UIScrollView and an UITableView?

Is is possible to implement smooth scrolling using both a UIScrollView and placing a UITableView at somewhere starting in the middle of the screen? The UIScrollView contentSize is elongated to accomodate the additional height of the UITableView. The UITableView should be able to contain unlimited and unknown number of rows. Scrolling the entire view downwards will cause the upper non-tableview portion to first disappear and then it scrolls down just like a regular table view.
Put it in another way, I'd like to implement a table with some fixed content before the top row. Think of it like a "header area" for the tables, scrolls up and giving way to the entire table rows.
I probably know that I can implement a TableView and programatically make the first row to contain some fixed images. In this way, it will work as expected. But which is easier to implement?
You really don't want to put the table in a scroll view. When the user scrolls on the table it will not move the underlying scrollview so you won't get the effect you are looking for.
Implement viewForHeaderInSection instead and pass in the view you want to display above the first row, or set tableViewHeader.

iPhone: How to Place a Scrollview Inside of Tableview Cell

I want to put a scroll view inside of the table view cell. I have a number of buttons in one cell of table view and I need to scroll that cell to show the appropriate button.
If you want to use a vertical scroll view then I wouldn't suggest you doing it because, as TechZen wrote, there will be a mess in this case.
If you want the inner scroll view to scroll horizontally then it might be achieved by 2 ways:
Implement a custom table view cell that will include a scroll view inside it.
Add a scroll view as a sub-view to your cell that you will return from tableView:cellForRowAtIndexPath: method.
I suggest you to use the second approach.
There are plenty of examples online. Usually the sub-views are labels or image views, but it is not complicated at all to add a scroll view instead...
I don't think you can do this. It would require nesting of scrollviews which isn't really supported.
Even if it was, it would be very difficult for a user to know which scrollview they were hitting with their pudgy finger. Remember, you don't have the one pixel precision of a mouse on the iPhone. You have an area of at least 15x15 pixels. You don't have a scroll bar but instead just drags anywhere on the screen.
Instead, you should use a master-detail pattern. Selecting the cell in the tableview pushes a detail view which has the scroll view with all the buttons.
Why do you want to do it like this?
I think the best idea is to draw your table view manually above your uiscrollview. I did it, and it works. It just takes more effort and drawing accuracy. But that takes a lot of time. :)

A UITableView followed by several buttons- any way to size the table view to fit a variable number of rows?

In Interface Builder, you have to set the size of the tableview and position the other elements beneath that. I want the tableview to be sized to fit any number of rows and the buttons to be moved down relative to the tableview.
Is it possible to do this without building the whole thing programmatically?
You should embed the buttons within a UIView, and set that UIView as the tableFooterView of the UITableView. You can do this in IB by dragging the view into the bottom of the UITableView. This way the buttons will always be below the last row of the tableview, though I should warn you that if there are more rows than fit on-screen, the buttons won't be visible until you scroll down. If this isn't what you want, then you'll need to do something more complicated (namely, run -layoutSubviews on the UITableView, then ask it for the rect of the last section, and use that to calculate where the buttons should go).