As I updated an app of mine from iOS6 to iOS7 I noticed that where in iOS6 cell content was allowed to cross outside of a cell when the clipsToBounds property is set to NO on the cells view or contentView, iOS7 seems to disable this even when the overall view, tableview, cell and cellcontent clipsToBounds are all set as NO. You can see a sample of this in the included images. The first is test code running on iOS6, and the second is the same code running on iOS7:
Does anyone know how to fix this issue? I'm guessing it's just a one-line fix, but I've spent several hours on this with no luck. To avoid a major rewrite and headaches I'd, but playing around with the view, tableview, cell and cellcontent clipsToBounds has been fruitless - all are set to NO still on iOS7, so I'm not sure what is happening differently.
You can see and download the sample project at: https://github.com/Jon-Schneider/ClipsToBoundsTest
Thanks!
It looks like the view hierarchy changed slightly in iOS 7 for table view cells.
You can try setting the clips to bounds on the contentView's superview:
[cell.contentView.superview setClipsToBounds:NO];
If you add the following to your sample code and run on ios7 vs ios6, you'll see there's an additional view between the cell view and content view:
[cell.contentView.superview setClipsToBounds:NO];
NSLog(#"%#", cell.contentView.superview);
NSLog(#"%#", cell.contentView.superview.superview);
NSLog(#"%#", cell);
if (self.view.clipsToBounds) {
NSLog(#"Master clips");
} else {
NSLog(#"Master no clip");
}
You may made chang in the tableview attributes inspector of Clip Subviews.
Related
I have an app that uses custom tableviewcells. When I use autolayout for subviews (e.g. UIImageView, UILabels) on runtime I dont see any of the subview even though the constraint lines are blue. Everything was fine before i updated to Xcode8.
Constraints work fine on in other views.
EDIT: Here is the screenshot. Imageview is not displayed at all, even though it has placeholder image by default and there are images in source to replace the placeholder.
EDIT: same code without constraints.
I had a similar problem when using custom table view cells and auto layout. Somehow when I called [self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:#"cell"] the cell wouldn't show. However once I removed this line from the viewDidLoad: everything worked properly
It's not certain that you have things layed out this way but this is what worked for me. Also, if you use anything like an autoresizingmask, turn that off for your constraints to work. You could also try selecting the Content View of the cell in interface builder and deselect "Autoresizes Subviews".
I do not remember the first time I saw this bug. If it started with the iOS 9 framework or not.
The problem is when I have an UITableView as first child of my UIViewController in Storyboard the tableView apparently have a bigger content size and do not show the scroll indicators. When I put a transparent UIView as first child, the problem disappear.
The same issue occurs with UITableViewControllers. And there is no trick because de TableView is the main View of the ViewController.
Anyone got this bug too or know how to fix it?
I am trying to resolve this problem in order to prevent future problems just because the Storyboard is in "MacGyver mode".
Looks like the frame of the table view is bigger than the screen size. That's why no scrolling indicators appear. When you add a transparent view as the superview of your table view, you're somehow influencing the resizing of that table view. Try inspecting the frame of the table view and then play around with its layout constraints.
Update:
I've taken the PO's code and found out that (on iPhone 6 simulator) the table view has frame = (0 0; 375 667) and contentSize: {600, 0}. This is the answer why no scrolling indicators appear. The content size is "wrong" because no data source has been specified.
And then, when I specified a data source and returned 28 for row count on section 0, I got an exception. That exception said: "failed to obtain a cell from its dataSource". That was because UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; returned nil (that was expected BTW). The right way of instantiating table view cells is this:
- (__kindofUITableViewCell * _Nullable)dequeueReusableCellWithIdentifier:(NSString * _Nonnull)identifier
... but it's a completely different story. Hope this helps.
The problem was occurring because in some point of the project an UITabBar of UITabBarController was override and the bottom layout guide was affected. Now, I just hide the native tab bar and put the views that I need on top of it. In this case, the native Tab Bar still there, hidden but there, so the layout guides.
In order to get my app in line with guidelines for iOS8, I've implemented auto layout in my custom table view cell. On iOS8 this looks fine - the cells are laid out as I'd like at all screen sizes. On iOS7 however, the text boxes start out with only one line of text each, with the remaining text cut off (with an ellipsis). When touching the button however (on touch down), the cell's layout changes and it looks more like it does on iOS8. I can't seem to find what is being called here, and there aren't any constraint errors/warnings coming up in the console. Any idea how I might debug something like this, or is this a known bug in iOS8 so far?
I've noticed too when using self-sizing cells made in a storyboard. I was able to get it to work correctly by calling layoutIfNeeded in the cell's didMoveToSuperview method,
-(void)didMoveToSuperview {
[self layoutIfNeeded];
}
I have a navigation view and my second view will contains a table with custom UITableViewCell in it .
I have 2 issues
when i am trying to open the application in Horizontal orientation (navigate to 2nd view ) and then Rotate the device in Portrait mode then i am getting a scroll in the Table View portion.
when i open the 2nd view (in navigation) in portrait orientation and then rotate the device to horizontal and tries to swipe to get the delete button ,its not working particularly in Horizontal orientation.
Delete buttons are covering my labels
I have used , custom UITableViewCell, AutoLayout and Storyboards
I have also uploaded my project for reference
Link
Thanks in advance. !!
All the issues described by you are caused by bad layout. I have downloaded your project and corrected them. What I did:
1. Disabled autolayout. I did that for simplicity. This probably can be done with autolayout as well, but in this case it is much simpler without it.
2. Fixed autosizing for table view and the top label.
3. Fixed autosizing for the labels on table view cell. This fixes the delete button issue.
You can download the fixed project here.
EDIT:
If you want to use autolayout you have to write some custom code as described in this answer.
NSDictionary *dict = NSDictionaryOfVariableBindings(myLabel2);
[cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:[myLabel2]|" options:0 metrics:nil views:dict]];
I have checked the code with your project and it worked. You can download the autolayout version here.
EDIT 2:
To fix the rotation issue you can just reload the table view after interface orientation change:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
UITableView *tv = (UITableView *)[self.view viewWithTag:200];
[tv reloadData];
}
Check it out here.
I'm working on project targeted for iOS 6 that leverages storyboards and auto layout. In the storyboard there are many places where a UITableView is added as a subview to a view controllers view. This table view uses prototype cells from the storyboard.
The issue we're running into is that if the view controller is initially loaded in landscape orientation and the device is then rotated to portrait, the table view begins to scroll both vertically and horizontally. The table views cells are drawn with the correct dimensions but there is additional white space to the right.
It appears that while the frame and bounds of the table view are being updated to the correct size on rotation, the table views content size is not. Regardless of any update rotation change the content size remains the same dimensions.
The issue doesn't present itself if programatic table view cells are used.
A few garish work arounds I've found, 1.) calling reloadData or reloadRowsAtIndexPaths:withRowAnimation: 2.) manually setting the property contentSize.
Both of these seem less than ideal.
I've added this
link to a dead simple sample project which demonstrates this issue. The only changes made are to the storyboard and the main view controllers implementation.
Before rotation
After rotation
I'm having the same issue - can't seems to find any documented answer related to this. I ended up manually modifying the UITableView contentSize like you mentioned in:
- (void) viewWillLayoutSubviews
{
self.tableView.contentSize = CGSizeMake(self.tableView.frame.size.height, self.tableView.contentSize.height);
}
I ran into this issue today and filed a bug report with Apple.
Appears that if you are using a custom cell with a UI element AND autoLayout, the UIScrollView content size is having problems.
If you remove all UI elements, OR turn off autoLayout, OR use a factory cell (basic, etc), all works fine.
Same issue I have rectified in my project.
I guess this is a bug in Storyboard.
Then I have solved it by manual coding in willAutorotate method by setting
tableview.contentsize = CGSizeMake(tableview.width, tableview.contentsize.height);
Hope this will work for you as well.
If you find any apple documentation regarding the same then please update me as well. Till then you can use the same solution.
Appears that if you are using a custom cell with a UI element AND autoLayout, the UIScrollView content size is having problems.
I had to turn off AutoLayout for my custom UITableViewCells to be able to scroll to the bottom on updating the data and then [self.tableView reloadData].
With AutoLayout turned on, the tableView.contentSize was being updated, but I still wasn't able to scroll to the bottom unless I rotated the device.
I found the following to work for me:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
dispatch_async(dispatch_get_main_queue(), ^{
self.tableView.contentSize = CGSizeMake(self.tableView.frame.size.width, self.tableView.contentSize.height);
});
}
Notice the async dispatch: if that line would be executed synchronously then the contentSize change would trigger another layout pass before the current one would have completed. This triggers an exception:
Auto Layout still required after sending -viewDidLayoutSubviews to the
view controller.
Usage of Constraints helped me. Since you are using Storyboards, it is really easy to set Constraint values for all edges, so UITableView will always fill the whole ViewController (of course if UITableView fills whole ViewController) regardless of device orientation.
I had the same problem.
I found this link. When I tried to implement this I did not find the Auto-sizing attributes for my view then I clicked on Master View Controller and then clicked on the File Inspector and uncheck Use Autolayout and then go to Attributes inspector auto-resizing should be there then you can change the attributes how you want it.
I am sure you must have managed to figure this out.