Is it possible set width of UITableView or cells on iPad - ipad

Since it's not possible to "hook onto" this and get an answer, and none of the answers do it, I thought I'd ask if anyone ever succeeded in doing it and if so, how.
I've created a New File, selected subclass UITableViewController with XIB, and everything works fine. I can set the height of everything (with delegate methods), but not the frame of anything.
Right now the table is as wide as the iPad and it looks kinda corny with the short titles in each cell - and there is nothing in IB that changes the stretching or layout.
I'd be happy with any solution that causes the cells to shrink horizontally - like margins. I tried scrollview insets in IB, but they only add to the size of the scrollview so it gets bigger than the screen.

I think that you want to subclass UViewController and add a UITableView to it, and make it the size you want in IB.

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.

Resize UITable Header View Auto Layout

I am building a simple iOS application using Swift.
One of my views, displays a list of comments (cells in a PFQueryTableViewController...I am using Parse.com for my database).
My cells resize happily in order to fit the possible multiple-lines of the comments. This is MAGIC! (if you ask me)
What I am having trouble doing, is making the UIView which is at the top of the TableView resize based on multiple lines worth of content for the Label in that top view (see below).
Instead of doing multiline and resizing the view (I have set up constraints and set lines of text to 0), the label only shows one line, truncating it at the edge of the screen with "..."
Does anyone have any suggestions or solution for how to cause my top UIView to resize based on the content of the UILabel?
I was also thinking this could maybe better be done using a Container View at the top of the TableViewController?
There is a delegate method in UITableViewDelegate that lets you return the height of the head view (heightForHeaderInSection). You have to implement it making sure you return the proper height.
If you have a nib with constraints already, you can load the nib in a #property, and use the method systemLayoutSizeFittingSize that should give you enough height.
For more details checkout this post I wrote a while ago: Customize the UITableview with different height of cells like Facebook feeds in iOS

Padding between UITableViewCell and its subview (UICollectionViewCell)

I've been futzing around trying to get some padding between the bottom of my subview and its container UITableViewCell. I have an xib file, but changes to that don't seem to affect my actual ui (i've had to pragmatically change the tableviewcell height, for example).
I've also tried a few examples on SO regarding adjusting the center value of the subview, but no cigar.
Any ideas?
Thanks in Advance.
So, I decided to just move the individual elements within the inner cell which is less reusable than just adjusting the whole cell, but.. It will do for now!
Cheers.

Adjusting the UiTableview hight in IB so the the table its able to scroll all the rows

I have a UITableView that is cutting off the last row and a half. I assume this is due to the face that I am using a navigation controller. What I can't figure out is how to adjust the height of the TableView so that it works on both iPhone 4 and 5's. If I adjust the height in IB to fit the iPhone 4, I have a large gap on the bottom of the iPhone 5. I would think there is some automatic way of doing this, but nothing I am trying seems to be working.
Auto Layout - Official Guide...
Also, if you're using a UITableViewController on the storyboard, this will solve your problem (with or without navigation controller, which is unrelated). If you're using a UITableView on a regular UIViewController, however, the best answer is auto-layout.

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.

Resources