UITableView frame going out of view - uitableview

I have a application that I'm developing in swift. I added a UITableView in a ViewController. The UITableView frame is going out of view in width. I have already checked that the width of TableView in Interface Builder is within the view.

Related

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.

Set UITableView frame height based on numberOfRows?

I create the UITableView in the Interface Builder, and in my VC viewDidLoad method I resize the tableView via tableView.frame.size.height = 65*numberOfRows but it does not change the frame of tableView. I also tried moving the code to viewWillAppear but it doesn't work either.
Because of some design issue I don't want to set the tableView scrollable, so I want to resize the tableView frame based on its row number.
Is there any way to resize a UITableView created in IB?

Dynamically setting size of frame of a UITableView which is placed in UIScrollView

I am using swift and have a story board containing a UIViewController which includes a UIScrollView with UITableView.
What am I trying to do is to load an excel file in a table so I need to scroll horizontally. I can set the content size of scroll view with:
scrollView.contentSize = CGSize(width: 3500, height: scrollView.contentSize.height)
I do also need to set the size of frame of UITableView. When I set it from storyboard with the field shown it works, but when I set it programmatically from viewDidLoad method it does not work. The width value is shown as changed to 3500 but when I checked in tableView cellForRowAtIndexPath method, I see the value set in story board.
Here is a sample project I just created to see if I could create what you are asking for.
https://github.com/joalbright/Excel
Apple Documentation discourages you from embedding UITableView inside UIScrollView.
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.
Anyway are your UITableView and UIScrollView scrolling horizontally?

UITableView and Another View inside ScrollView

I have UITableView and UIView(used to show image slideshow) inside UIScrollView. The tableview is dynamic and i want to automatically adjust height of table view to show all the cells(and disable scrolling of tableview) and scrollview should show both slideshow and tableview and could be scrollable, I know how to do this with code but i want to know if is possible to do in Interface builder(without using iOS6 auto layout) using previous(iOS5 and early) autoresize method in the xcode size inspecter tab(see image)
I think this is hard to do only using interface builder.
You can set your objects via interface builder. But for maintaing scrolling conditions you need to do it programmatically. Also for table view height to be dynamic you need to be done programmatically.

iPhone + resize UITableView

I have a view in which I have UITableView (grouped style). In the Interface builder, I am resizing the UITableView so that it looks like a small portion in center of the screen.
But when I run the application, UITableView takes up the whole area of screen and does not look like the small portion in center of screen (which I had set in Interface builder).
I tried to resize the tableView programmatically in the viewDidLoad method as tableView.frame = CGRectMake (0.0,0.0,100.0,100.0), but still the tableView occupies the whole area of screen.
Please help.
Regards,
Pratik
Sounds like your table view's got autoresized. Try to fiddle with the autoresizing settings.
If your table view is the main view then it will automatically fill the whole view controller's space regardless of the autoresizing settings. In that case, make an empty UIView as the root view and put the UITableView as a subview of it.

Resources