UITableView as subview of MKMapView - ios

I would add a UITableView under an MKMapView, and make it resizable as the orientation of the device changes. Also, the table should hide/show as per user request.
I succeed in adding the subview, either in IB and in the code, but the problem is that when I change the orienation from portrait to landscape, the table is not properly rendered.

You can design and use another xib file for landscape mode or use autoresizingMask.

Related

Auto-Layout UIScrollView and an animated UIView

Currently having an issue with using auto-layout and UIScrollView. The issue is when I scroll down on the scroll view, a previous UIView (that should be free roaming, and is animated to various positions) gets set back to its initial location where it is located in Storyboard.
What's the best way to make my single UIView not follow the behavior of auto-layout and let it do whatever it wants to do?

Rotations in iOS if UIViewAutoresizing doesn't cut it

I'm creating a view controller that has non-trivial rotation behavior. I can't find a way to get all my transformations to occur with only UIViewAutoresizing (I'm doing things like keeping by bottom bar at the same "absolute value" on the screen" while rotating buttons). What's the correct way to handle these type of rotation behaviors? Is there a way to disable auto resizing for a specific view and handle the rotations yourself?
If you set a view's autoresizesSubviews property to NO, that view will not apply autoresizing to its subviews. You can do this in a xib or storyboard by unchecking the “Autoresizes Subviews” checkbox in the attributes inspector.
The correct place to programmatically lay out subviews is in the layoutSubviews method of your custom UIView subclass. Your view will receive the layoutSubviews method whenever its size changes or when its subviews array changes. You will receive it when the view is first being put on the screen, and inside the autorotation animation block.

Uibutton contraints in two layouts

I’m still trying to get my head around constraints and the objective c best practises in general.
I need to dynamically create between 1 to 6 UIButtons depending on a variable. I’m ok with this part but confused with how to position them given that:
The number of buttons could be anything from 1-6.
The buttons have to be of equal size.
Landscape and Portrait orientations will have different layouts.
They have to ‘float’ left in the landscape view and vertically align to the top in portrait view.
I'm guessing I'll need one container that sits at the bottom of the view and changes height depending on the orientation, then have rules for the buttons inside depending on the container width. But how to go about it I have no idea.
In the long run it will be better to use the UICollectionView. Subclass UICollectionView and add it in your Storyboard. Make an outlet of the collection view to your view controller and set its delegate and data source. Add the <UICollectionViewDelegate> and <UICollectionViewDataSource> to your view controller and implement the delegate methods. For the buttons, make a custom UICollectionViewCell with a UIButton as its subview. Then in cell:ForRowAtIndexpath: method, initialize the UICollectionViewCell subclass, and set the properties of the UIButton. This might not be the answer you wanted, but UICollectionView offeres much more flexibility as far as layouts are concerned. You can read more about UICollectionViewDelegateFlowLayout here.

UITableView rotation issue

I have UIViewController with a UIView with UITableView inside.
All works fine in Landscape mode but when the device is rotated to Portrait, bottom half of UITableView is not accessible (can't even select any row in the bottom half or make table scroll). All rows are displayed correctly.
I am re-framing and repositioning UIView and UITableView on rotation.
Any ideas how to solve this problem?
You should adjust the autosizing in Interface Builder or in code.
I think the UITableView's height is still same with the value in Landscape mode after you rotate device to Portrait.
You can identify it by NSlog your UITableView's CGRect
NSlog(#"frame:%#",[NSStringFromCGRect(UITableView's CGRect)]);

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