I want to fill a popover with a UITableView. The height of the popover varies depending upon the orientation of the device etc. How can I set the UITableView properties so it always fills the available size of the popover, and vertically scrolls when necessary?
#H2CO3 is correct.
In your action when you present the popover, do something like:
mytableView.frame = myPopover.bounds;
That way, your table view will match the popover it is in.
Then when you want it to scroll do this:
[self.tableView setScrollEnabled:YES];
Related
I have a container view created in a xib, I have added various textfields to that container view, In a case when the user reaches that view controller I want the container view to automatically scroll to a particular textfield and focus on it.
Note that I am not using scroll view as of and I am trying to know is there a way to do it without using UIScrollView
There is no ability to make a UIView scroll in of itself. I would recommend using either a scroll view or a table view. If you decide to use a table view, you would have your textfields in individual cells, then you could do something like this to scroll:
//Scroll to 4th text field
NSIndexPath *indexToScrollTo = [NSIndexPath indexPathForRow:3 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexToScrollTo
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
In a scroll view, you would set the content offset to scroll to a particular y position. Here's an examle:
//Scroll down by 50
self.scrollView.contentOffset = CGPointMake(0,50);
yes,you can do it by using TableViewController. it automatically focus on the text fields and automatically scroll up when keyboard appears.
I have a UITableViewController and I put a UIView right under the navigation item and above the actual table. The problem that I have is that the view scrolls with the tableview.
How would I get it to behave exactly like the nav bar, and have the items in the tableview scroll behind it.
Rather than having the view scroll, it should remain in its position and have everything go behind it. Sorry for reiterating, but I've found thats necessary sometimes.
The view you're placing above the cell in the storyboard becomes the table view's tableHeaderView.
You can make the header view appear fixed by resetting its frame.origin to the table view's bounds.origin every time the table view lays out its subviews:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
UIView *header = self.tableView.tableHeaderView;
CGRect frame = header.frame;
frame.origin = self.tableView.bounds.origin;
header.frame = frame;
}
Result:
Assuming you don't want the map view to move then you could set its user interaction to false.
Alternatively you could set the header of your tableView (if you only have one section) to the map view.
I want to get my UITableViewController to scroll only when there is not enough room on the screen for all of its cells. I am using static cells that are designed to be shown in an iPhone 5, 6, and 6 plus size screen. However, when shown in the 4s screen, the bottom cells get cut off.
Ideally I would like to use AutoLayout to anchor the bottom of the tableview to the bottom of its superview as I have with other tableviews in my application, but Xcode doesn't allow me to add constraints to the UITableView in a UITableViewController. The reason I have to use the UITableViewController is because I am using a pod for a slide menu (https://github.com/SocialObjects-Software/AMSlideMenu) that subclasses UITableViewController.
I have tried to change the size of the UITableView's frame based on the screen size because I assumed a scroller would automatically be added if the cells took up more room than the containing frame. I used the following code to do so:
CGRect frame = self.tableView.frame;
[self.tableView setFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, [[UIScreen mainScreen] bounds].size.height - HEADER_HEIGHT)];
However, it had no effect on the way the table was displayed.
Does anyone know how I might be able to set the bottom of the UITableView dynamically and add a scroller to the cells when the screen is too small? I would also welcome any suggestions that might help avoid having to do this at all, as I would prefer not having to do anything too hacky.
You can set the alwaysBounceVertical property to false so the tableView will only scroll when its contentSize is larger than the table view's frame which you can constrain to your view however you like.
tableView.alwaysBounceVertical = NO;
UITableViewController height is determined by automatically calculating number of UITableViewCell you have presented. You can customize the cell height so that height of UITableViewController will automatically changed as you wished.
I am using a UICollectionView with fixed size CollectionViewCells. I display this CollectionView in a popOver with an UIPopoverController.
My goal is that the popOver automatically resize to the CollectionView's content. So if I only have 4 cells, than it should be small. And if I have more cells, it should be bigger. I want to avoid the empty space left in the popOver.
So I don't want a fixed popOver size, but a variable one depending on the number of cells in the CollectionView.
Any suggestions?
I had a hard time figuring this out myself but just got it finally. You have to access your Collection View's collectionViewLayout property and then use the collectionViewContentSize method to get the size of your content. You can then use those to resize your Collection View by setting it's frame.
CGRect rectangle;
rectangle = _collectionView.frame;
rectangle.size = [_collectionView.collectionViewLayout collectionViewContentSize];
_collectionView.frame = rectangle;
Now that your collection view is sized to it's content, you can set the popOver's size based on the collection view size. It may look something like this.
popOver.frame = _collectionView.frame;
or
[popOver sizeToFit];
I am developing an iOS application, and I want to add a search button that initiates a search of a table view. When searching, the search bar should not be scrolled with the table cells.
To make a search bar (or any view really) "stick" to the top or bottom of a UITableView there are two approaches:
Adjust the frame of the table to be the view height minus the height of your bar, and then set the bar's frame to {0, 0, CGRectGetWidth(self.tableView.frame), CGRectGetHeight(self.tableView.frame)}, which would position it statically at the bottom of the view. If you are using a stock UITableViewController, you'll need to do some additional work because self.view and self.tableView both point to the same object. You'll need to set a new UIView to self.view which will then be the container for the table view and your search bar view.
Add the bar as a subview of table, then implement UIScrollViewDelegate in your controller and use scrollViewDidScroll: (which fires whenever the user scrolls the view) to update the bar's position. The new position would be something like:
CGRect adjustedFrame = self.searchBarView.frame;
adjustedFrame.origin.y = self.tableView.contentOffset.y + CGRectGetHeight(self.tableView.frame) - CGRectGetHeight(self.searchBarView.frame);
self.searchBarView.frame = adjustedFrame;