iPad - UITableView with UITextField - Autoresizing problem when orientation changes - ipad

In my iPad split view application, I've a table view in detailed view as well. Each row has a text field. When orientation changes, the table field in table view is extending out of table view.
Can some one tell me how to set the auto resizing mask so that even when orientation changes, the text fields will be within the table view?

if you add tableview as subview of UIView then:
[self.view setAutoresizesSubviews:YES];
[tableView setAutoresizesSubviews:YES]; or set in IB
while creation of cell set like this:
[urcell setAutoresizesSubviews:YES];
if u add textField as subview of cell. So that it will handle all of its subviews while orientation

Related

Getting collection view cells to update after a constraint change

I'm having a problem with auto layout in a collection view cell in iOS 9.
During the collection view's :cellForItemAtIndexPath: I change a constraint:
[[self rootStack] setDistribution:UIStackViewDistributionFillEqually];
or
[[self rootStack] setDistribution:UIStackViewDistributionFillProportionally];
During the cell's preferredLayoutAttributesFittingAttributes: I try to force an additional round of layout:
- (UICollectionViewLayoutAttributes*) preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
[self setNeedsLayout];
[self layoutIfNeeded];
return layoutAttributes;
}
Still, when cells are displayed, some show the effect of the constraint change and some do not. If I scroll a cell that does not display the change offscreen and then scroll back to it, it then displays the change. Moving the constraint changes to the cell's updateConstraints resulted in none of the cells showing the change on first display.
I can fix this for the first cells that are displayed by calling reloadData on the collection view during the collection view controller's viewWillAppear:. But once I start scrolling some of the cells that come into view are not formatted correctly (unless I scroll past them and then scroll back to them).
Is there a way I can make sure that all cells are formatted correctly the first time they are displayed?

How to clip table view cell to view above

I have custom tableViewCell and View above it in tableView. After taping on button views height increase and cover cell's view. How to clip cell to bottom of view for changing position of cell and don't allow view to cover cell?
I tried to override setFrame: method in my cell. But it doesn't work.
If the view above the cells is a table header view, you should reset that view as the header after you increase its size. So, if you're view was called myHeader, you would do this after changing the size ,
self.tableView.tableHeaderView = myHeader;

resizing uitableview on orientation change does not resize correctly

I cannot resize the uitableview properly when changing the orientation of the screen. I can make one orientation work fine but not both.
I've tried 2 different methods: 1) using the autoresizingMask on the tableview and 2) using the layoutSubviews method and here are the results of each:
1) using the autoresizing almost works if I use
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;
It shows correctly when in portrait and then I move to landscape it also shows correctly but not all the way to the end of the screen. In landscape I see a space on the left side and on the right side.
So, I thought let's just add the UIViewAutoresizingFlexibleWidth to the line of code above. It does make the uitableviewcell expand to the full screen in landscape but when I change the orientation it does not maintain the same cell on the screen and sometimes it displays half of one cell and half of another cell in the middle of the screen.
2) Using auto layout. I get the same behavior as above when I use this code:
-(void)layoutSubviews {
[super layoutSubviews];
onLoadSize=self.contentView.bounds.size;
self.myTableView.frame = CGRectMake(0, 0, onLoadSize.width, onLoadSize.height);
self.selectedBackgroundView.frame = self.myTableView.frame;
}
If I add an if statement testing for the orientation, then it works fine for that orientation in specific but not the other. If I test for both orientations I get the same behavior as described above.
Any help will be very welcome.
Thanks!
UITableViews usually occupy the full space of the parent view controller and typically don't need constraints or active resizing, unless you have more than one table view in a single view.
Consider managing the content of UITableViewCells (instead of managing the table view) by:
(1) Applying constraints to each custom cell in Interface Builder.
(2) Redrawing the cell's frame to fit the parent UItableView when the cell renders its subviews (layoutSubviews method).
(3) Calling [cell.contentView needsUpdateConstraints] to force the cell contents to redraw.
Here is some sample code for cell's custom class:
-(void)layoutSubviews
{
resizeCell:self forView:[the cell's UITableViewController.view]
}
Here is a generic function you can add anywhere for reuse:
-(void)resizeCell:(UITableViewCell *)cell forView:(UIView *)view
{
cell.contentView.frame=CGRectMake(cell.contentView.frame.origin.x,
cell.contentView.frame.origin.y,
view.frame.size.width,
view.frame.size.width,
cell.contentView.frame.size.height);
}
Please note the cell's UITableViewController must be passed to the cell's custom class (as a member variable) for the code above to work.
Good luck!

TextField subview not resizing w/ UITableViewCell frame size change

Have a storyboard w/ a TableViewController that has a grouped table view. In the first section, I want the cells' width to be smaller than full-screen. To accomplish the latter, I have a custom UITableViewCell class w/ the following method:
- (void)setFrame:(CGRect)frame {
frame.origin.x += NAME_TABLE_VIEW_INSET;
frame.size.width -= NAME_TABLE_VIEW_INSET;
[super setFrame:frame];
}
That works fine. The issue I have is that a UITextField subview that I dragged into the storyboard cell does not adjust its width automatically to the new cell frame size.
I've tried sub-classing UITextField and ensuring that the autoResizingMask is set properly, and I've tried using [super layoutSubviews] in the setFrame method above. None of these approaches works.
Any suggestions on how I can get the text field to adjust its width automatically while still using this storyboard approach?
The solution for this was to add a separate table view in the header of the tableView provided by the table view controller. Specifically, add a view object to the top of the table view in IB; add a table view as a subview into that view; change the width of the new table view's cells.
Note that this problem exists only because I wanted to use a table view controller, which defaults each cell to the width of the screen. A view controller could have been used, but then you cannot add a table view w/ static cells as a subview.

How to set a UITableView frame so it fills a popover

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];

Resources