iOS: TableView and Sizing issue - ios

I have a UITableViewController class for a simple table view(like a 2-4 cells User ID and Password,... )I represent this table view with "presentModalViewController" and the problem is the table view's width will be fit to whole screen's width and I want to make it smaller and be in a center of screen.I used the "viewWillAppear" and tried to set the self.tableView.frame to a CGRect like (150,150, 500, 600), now there are 2 problems 1) the x and y of new table view is alway( 0,0) the second issue is the frame of tableView has different color than background. how can I fix these?
Thanks,
Kam

the problem is the table view's width will be fit to whole screen's width and I want to make it smaller and be in a center of screen
Then don't use a UITableViewController. The docs on UITableViewController clearly say this: if a table doesn't occupy the whole screen, use your own UIViewController subclass instead.
What you want, probably, is a UIViewController whose view will occupy the whole screen, as usual - and that view contains a table view placed in the desired location.

Related

Stop UICollectionView hiding cells out of view bounds

I have a horizontal-scrolling UICollectionView which is nested in a UIView that is centred and occupies 80% of the screen width.
I want the UICollectionView to be visible screen edge-to-edge rather than constrained to the super UIView bounds.
I have set the following which shows the UICollectionView across the screen width:
collectionView.clipToBounds = NO
...but when dragging the collectionView, it hides cells when they are completely outside of the super UIView bounds even though they are partially visible on the screen, which leads to a weird flickering of blank space/cell.
Ideally, I'd like a way to prevent the hiding of the cells completely out of bounds. Is there a way to do this?
The UICollectionView has a maximum size of 3 cells, so I'm not particularly worried about any performance implications of having all cells visible all the time.
The only way I found is to enlarge the frame of the collection view (and its superview in your case) and add contentInset's to it. You might also want to update scrollIndicatorInsets.

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.

Content in UIScrollView is being cutoff early

I have several UIViews within aUIScrollView and I want them to scroll all the way to the bottom of the UIScrollView before cutting off (See Image #2).
Background on the scroll view:
I created the UIScrollView itself is a subclass of a customUIView. I put the view in a UIScrollView so the auto layout in storyboard creates the correct frame for the device.
In the view controller attached to the storyboard UIViewController I created anIBOutlet to theUIView, and in the viewDidAppear function I called a function attached to the view that populated the UIScrollView.
In the storyboard I gave the view a blue background so I could tell its frame. Here is the what the storyboard looks like:
Then this is what it looks like on my phone:
Notice how much space exists between where the view cuts off and where the bottom of the screen is. It does this on all devices.
I have tried adjusting the bottom content inset. It is currently at 0.0 but I tried to make it -20 and that did not help.
How can I fix this?

Custom Sized Table View Still Using Offset For Navigation Bar

I am making a viewController that to input information Name (UITextField) Desc (UITextView) and then add time slots for each task (TableView) however when I add the viewController to my navigation Controller it adds an offset to the UITableView as if it were suppose to fill the page.
I have tried changing the offset but that only results in moving the massive white space further up the page and another white space appears below (I'm assuming its from the tab bar controller). how can I get rid of this offset?
I would suggest do the following:
Frame your tableView to occupy full view frame.
Use contentInset and scrollIndicatorInsets to reduce the actual table size to the proper size. In your case make sure top edge for contentInset and scrollIndicatorInsets are equal to the size of your textview and textField.
figured it out with an apple example they wrap their add a tableViewController to a UIView by adding the tableViewController as a childViewController of the UIView or if you are using storyboard u can use the container view

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