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.
Related
I have created a custom gallery with collection view which shows all the Photos of camera roll from photos app. I have made a custom cell class. Now the thing is happening like below - : It is not showing my last row of cells. Please folks help me out with this.
It could be great for me. I am not using Constraints for my UICollectionView. I am not able to figure out ; how to give content size to UICollectionView like UIScrollView.
Guys some time problem seems way bigger than they looks.
I figure it out and yes it solved mine.
I was searching the simple and short solution for this and I found same related question below - :
UICollectionView not able to scroll to see the entire last row
and the answer given by #Carpetfizz really worked for me.
I was using auto layout thats the reason it was solved ;
If you are not using auto layout it won't work for you.
Please enable Auto layout in your xib file
If you are using constraints, create NSLayoutConstraint IBOutlet for height of collection view. Then do this thing
[collectionView reloadData];
layoutConstraintCollectionViewHeight.constant = collectionView.collectionViewLayout.collectionViewContentSize;
It will automatically resize you collection view height and can scroll upto last item.
For non-constraint design, use this
collectionView.frame = CGRectMake (x,y,w,h); // Here calculate your height and width for collection view
[collectionView reloadData];
I have some modal controllers that are UIViews and are not scrolling.
Reading on SO, the apple docs and elsewhere, it seems there are three approaches to fixing this:
Multiselect all the elements within the view and then go
editor-embedin-UIScrollview.
change the view to a scrollview in the identity inspector and then
add the following line to viewdidload:
[(UIScrollView *)self.view setContentSize:CGSizeMake(320, 2000)];
Copy elements to clipboard, delete the uiview, add a new scrollview
and copy the elements into the scrollview. Warning - this destroys
the positioning of the elements although it does preserve their
outlet properties.
However, I have tried all of these and the scrollview still does not scroll.
Is there any other step I am missing?
Thanks in advance for any suggestions.
Edit:
Getting scrollviews to work is not easy and there is much conflicting advice on the web.
I finally got this to work by setting the content size in a separate method as opposed to viewdidload.
(void)viewDidLayoutSubviews {
self.MainScroll.contentSize = CGSizeMake(320, 1800);
}
Thanks as well to Evo for advice on setting all the vertical dimensions correctly and using freeform in the VC size inspector as it won't work if you don't carefully set these.
If you have EVER enabled autolayout, even if it's disabled now, you need to:
Select the view controller you plan on scrolling
At the bottom right of the storyboard view, click the third button (far right) and then "Reset to Suggested Constraints"
Make sure that all the elements in the scrollview are embedded in the desired positions.
If you are not using autolayout:
Check that the Size of the view controller is set to (320, 2000), or whatever you want.
In the Simulated Metrics of the view controller, you can set the size type to Freeform.
Then in the tab to the right of Simulated Metrics, you can set the width and height to the desired values.
Please comment any concerns
In Interface Builder :
I am not using Autolayout.
I place my UIScrollView and then drag in other elements into the UIScrollView
When I run my app in the simulator, the subviews of the UIScrollView are positioned in the center of the UIView instead of where I placed them at.
One item is a UITextField and if I dismiss the keyboard, the view repositions itself to how I set it up in Interface Builder.
How can I fix the initial issue of all items being placed in the center of the UIView?
Edit:
If I NSLog the x and y of my UITextField, it shows the correct values of where I set it in Interface Builder, but when the view first appears, the text field is pushed down below that location.
In this case, the x is 20 and the y is 108
Solution:
I did have to check on the autosizing, but I also added the code below and it fixed my issue:
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
I am not sure whether this may help you..
Please try to check the Autosizing of every component in the uiscrollview. The issue may also occur because of the wrong Autosizing of components.
I face the similar issue and got fixed once I correct the Autosizing of every component.
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.
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.