UITableView doesn't show up in UIScrollView - ios

I've created a view with a UIScrollView, it has height 1000px. I've added a UITableView to the view, plus other labels and buttons. When I launch it, everything is in its place except the table. Can anyone fix my problem?
I've tried:
table.hidden = NO;
and
[scrollView addSubview:table];
but nothing happened.

The documentation for UIScrollView specifically says not to do this:
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.
I would suggest adding the other views you intend to put into the scroll view into the table as a tableHeaderView, tableFooterView, or as custom cells.

Related

UITableview frame changes after scrolling thanks to Autolayout

I'm working on a application where I have a UITableView inside a UIScrollview.
The TableView will display current games players are in, its inside a UIScrollView. I dynamically add cells to the UITableView for each game, but when I scroll the UIScrollView, the tableview inside it snaps back to its size set in the storybuilder.
This is because of autolayout, when I disable it, it doesn't happen anymore. However I do like autolayout for other views in my app. So my question is, how can I fix this problem?
Maybe someone can help me get on the right track.
Thanks
EDIT
I think I must explain my situation more, I will use an image where I can display what is happening
Explanation
Before and after scrolling.
As you can see I use the scrollview because there can be many games, so you'll have to scroll down to see them all. The TableView is just to hold the data, scrolling is disabled on that. After scrolling the TableView that says "JOUW BEURT" snaps back to its size set in the Storybuilder. This is because of auto layout like I said, but I don't know how to fix this.
You shouldn't put a tableview inside a scrollview as a tableview itself contains a scrollview and causes issues just like you are seeing when you have a scrollview inside a scrollview.
Remove the scrollview and this should fix your issue. If you are wanting to put content above the tableview or where you scroll down to view the tableview cells etc, consider adding a tableview header view that is added above the tableview.
Why did you place UITableView inside UIScrollView?
Check below
Check your constraints of UITableView and UIScrollView
Placing UITableView inside UIScrollView is somewhat strange
EDIT
You will just need to remove the scrollview and enable scrolling feature of the tableview. that will fix it
UITableView is already a subclass of
UIScrollView

Adding subview to UICollectionView - disables scrolling

I want to add a subview to a UICollectionView in order to make a left panel that scrolls with the collectionview.
Using
[self.collectionView addSubview:myView]
all touches become disabled and I can no longer scroll the view. I've read that adding a subview to a collectionView like this is bad practice.. is this true? Why does it disable touches from reaching the collectionView event when
userInteractionEnabled = NO
I'm trying to do this: imgur link by grabbing the frame position of the first cell in each section, and adding a dot with to myView with the same y value.
Thanks for any help!
Adding subviews using the addSubview: method to a UICollectionView is very bad practice. It can cause a lot of different problems in the normal behaviour of the CollectionView. It can obstruct the views underneath it, capture the touch events, preventing them from reaching the actual scrollView inside the CollectionView, etc. The subviews added using this method will also not scroll as the other elements in the CollectionView do.
The correct way to do what you want is to implement a new type of UICollectionViewCell for the dots, and compute their locations in the prepareForLayout and layoutAttributesForElementsInRect: methods. Basically you'll have either one or two cells in each row. Which ones will have two rows will be determined by you in the methods I've mentioned.
In fact, Apple's docs have a perfect example that's even more complex than what you're trying you achieve. You should check it out from this link.
May I know the purpose of that scroll view ? Because, if you're looking for a subview that displays only a label or image etc., You can use custom collectionview cell instead if I am not wrong... Hope it helps :) :)

Issue with row selection UITableView inside UIScrollView

I have a view controller with following layout:
Container View
UIScrollView
UITableView as a sub view of a UIScrollView
I have another UITableViewController in which I have a few rows and some methods when the row gets selected. Now I want to display this UITableview inside the UIScrollView. So I add the UITableView as a subview of UIScrollView. The table is displayed in the scroll view just fine, but when I tap in the scroll view to select the table's row, then row is being highlighted but the method is not getting called when the row is selected..
PBDashboardPickupTable *dashtable = [[PBDashboardPickupTable alloc]initWithNibName:#"PBDashboardPickupTable" bundle:nil];
[self.scrollView addSubview:dashtable.tableView];
Also I have set scroll view's delayContentTouches to YES and cancelContentTouch to NO from Interface Builder. Also userInteractionEnabled is set to YES... then why is the method not getting called when I tap the table view's row?
Apple specifically warns in the documentation to avoid putting a UITableView inside of 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.
Since UITableView inherits from UIScrollView, I would suggest you add any additional views you need as a tableHeaderView, tableFooterView, or as custom cells in the table.

UITableView will not resize after UITextField becomes first responder

I have two Scenes in my Storyboard that are nearly identical. Both are UITableViewControllers. Both have header and footer views. The header views have a UISearchBar and the footer views have a UIView that contains a UITextField. Each have only one prototype cell. One is prototyped as a "Basic" cell and the other is prototyped as "Right Detail" cell.
Here's the problem. When I click the UITextField in the footer view on the first scene, the table resizes automatically so that the bottom of the table is at the top of the keyboard. This allows me to scroll the table up so the footer view shows and the user is able to see what they're typing. The other scene will not automatically resize the UITableView so the UITableView cannot scroll the footer view to where it can be seen and the UITextField is hidden under the keyboard. I can't even manually scroll the table far enough since the footer is always at the bottom of the UITableView.
A little added info. The scene that works has many rows of data while the one that doesn't work only has a couple. I tried adding a number of rows until the table had enough to enable scrolling and it doesn't fix the problem.
I have checked everything I can think of and I can't see anything that would allow one of the views to let the UITableView to automatically resize to work with the keyboard and the other not. I must have overlooked something but I can't seem to find it.
Any help will be greatly appreciated!
Rob
I thought this problem was caused by copy-and-pasting from one view to another, but I had the same problem once I'd (in theory) fixed it.
The answer for me turned out to be simple: I hadn't called [super viewWillAppear:animated] in my UITableViewController subclass' viewWillAppear: implementation. Make sure you've got a call to the superclass' method and hopefully the problem will go away.
I am guessing the frame of the tableview is not being resized to the smaller size in the second case.
Print out the frame and content sizes in both the cases once its loaded, that should help you see if there is an issue.

UITableView as cell on another UITableView cancel the scroll

I have a UITableView that their cells are UITableViews (the root tableView is rotated to work in landscape, similar to the CoverFlow).
The tableview cells show fine, but I can't scroll it, I think because the root tableView capture all the touch events.
The horizontal tableview can show dozens of cell tableviews, so I need to preserve the ability to swipe left/right the root tableview but scroll down/up the cells tableviews.
Is this similar to what the Pulse app does? If the table view doesn't automatically handle this for you, you may have to subclass UITableView and implement your own gesture responders. Shouldn't be too difficult though—just handle flicks and drags. You could also try enabling/disabling user interaction on one of the table views based on user scroll/flick direction.
I finally put a UIScrollView instead of a UITableView. Everything work fine now:
self.floatingColumns = [[UIScrollView alloc] init];
self.floatingColumns.pagingEnabled = YES;
[self.floatingColumns setShowsHorizontalScrollIndicator:NO];
[self.floatingColumns setDelegate:self];
If you are looking for something like Pulse, this tutorial might help:
http://iosstuff.wordpress.com/2011/06/29/creating-pulse-style-scrolling-horizontally-scrolling-uitableview-as-a-subview-of-uitableviewcell/
It shows how to add horizontally scrolling tableviews to tableview cells. Pretty cool!

Resources