How to enable "AutoLayout" of iOS 6 programmatically? - ios5

How can I enable "AutoLayout" programmatically. Actually I have to create an app which should run on iOS6 and iOS5 but we can enable "AutoLayout" in the XIB in iOS 6 only and it will not work on the iOS 5 so I am checking the iOS version and using if else condition for the appropriate task according to the iOS. So if app would be running on iOS 6, I will enable the AutoLayout otherwise I will write the code for AutoResizing. Please let me know if I am unclear at any point.

If you want autolayout on iOS6 devices but not iOS5 (unuspported) but still want to use nib's, you have to keep separate nibs. One for iOS5 and one for iOS6.
When loading your nib, check if autolayout is supported by checking if the NSLayoutConstraint class exists:
if (NSClassFromString(#"NSLayoutConstraint"))
//Load iOS6 nib with autlayout.
else
//Load iOS5 nib sans autolayout.

Related

didSelectAnnotationView not called for ipad

I am working on universal ios app which runs on iPhone, iPad and iPod-touch. I have
implemented the code for annotation and on selecting this annotation a callout would be
raised. It works fine for iPhone but didSelectAnnotationView method not called for iPad.
Should i add any additional to work for iPad? Thanks in advance
In your code i think you just forget to set Delegate in checking of device if else condition. please check Properly. if didSelectAnnotationView called in iphone but not in ipad it means for ipad condition you not set mapView.delegate = self; for ipad Condition.
So please check properly and set its delegate if your code working for iPhone so that probability for your issue.
see if adding this helps. [annotationView setCanShowCallout:NO]

App not running in ios 5

Since i want the app to run in both ios 5 as well as in ios 6 ,I am trying to run the app in ios 5 which is working perfectly in ios 6 as i have used the autolayout feature but when i use to run the app in ios 5 it crashes since autolayout feature is not available in previous versions of ios .Is there any solution to fix out my problem ?
Answer will be appreciated.
If you want to run your app in iOS 5 then you have to turn off the Autolayout feature.
You can do that from Interface builder.
For more help you can refer this.
You Need to unCheck the Auto Layout.
And make sure you are changing here also.. select ios 5.1
You have to use AutoResizing mask for your view instead of autolayouts since autolayouts are supported iOS 6 onwards.Check the example below
If you are using iOS 6 or later , then u can create a separate xib for the iphone 5 called Retina 4 Full screen. You need to check this in your ViewController Size. Also to check for for both of these xib's . That means to run either of your xib's in iphone 5 or lower versions use these conditions whether in the AppDelegate or wherever you need to show another ViewController.
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
}
else if(result.height == 568)
{
}
the above code would check for the size of your iphone's screen and accordingly adjust.
Hope this has cleared your issues :).
PS:- Dont forget to add your iphone 5 splash screen i.e Default-568h#2x.png.

iOS 6 orientation changes have me totally confused

This is a universal app and I have the supported interface orientations for both iPhone and iPad targets set only to Landscape Left and Right. My root view controllers do not use a NavigationController and the xibs are landscape oriented views. The app is designed to only use the landscape orientations.
In application:didFinishLaunchingWithOptions I have...
if (([JLHelper isIPhone]) | ([JLHelper iPadPortraitRestricted])) {
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
In iOS 5 everything worked fine but In iOS 6 the view does not display in a landscape orientation on startup.
I understand that shouldAutorotateToInterfaceOrientation has been deprecated in iOS 6, but I do not understand why this affects the initial presentation. It appears to me that the root view is being rotated.
I have read many discussions on how to force landscape orientation in iOS 6 and am now totally confused. There must be a simple way to implement an app that only uses landscape orientation.
You can specify the supported orientations in the info.plist for iOS 6. Additionally you can implement the shouldAutorotate method and the supportedInterfaceOrientations methods (new as of iOS 6) to conditionally restrict orientations for iOS 6.
Note that if you want to continue to support iOS 5 you also have to have the shouldAutorotateToInterfaceOrientation... method in place. iOS 5 uses the old method, iOS 6 the new one, they can coexist.

Supporting iOS 4.3 to iOS 6.0

I already have the base code that supports ios 4.3 to ios 5. Now I would also like to support ios 6.0.
The present base code has modal views, hard coded CGRect's, and rotation is different for each view. So I would like to know whether we can support ios 4.3 to ios 6.0 with the same base code, by just tweaking some changes, or do we need to create a complete new target?
Like we cannot use auto layout of ios 6.0 if I want to support previous versions as it will lead to a crash.
Yes, we can do this by setting up the Deployment Target to iOS 4.3. But then, why do you need to support iOS < 5.0 as around 85-90% of devices are on iOS 5.0+. See this
Also, when you set up support for iOS 4.3 or even iOS 5.1.1, you would have to handle multiple things. For example, the method for Orientation,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
isn't called for iOS 6. It is replaced by the methods,
- (NSUInteger)supportedInterfaceOrientations
- (BOOL)shouldAutorotate
You would need all the iOS versions on devices and then test each and every aspect of your app.
Using Xcode 4.5 it is perfectly valid to use one code base for building iOS 4.3 - 6.0 apps, but as always the key is testing on real iDevices with the given operating system versions.
Yes it is perfectly fine and can be done to support ios 4.3 to ios 6.0 using the xcode 4.5.
And for the orientations in ios 6 have to do some work around like have to put some code differently as posted in #Mayur J's answer.
Or all you can do is just add categories for the required controller's like UINavigationController, UIPopoverViewController, UIImagePickerViewController, etc to return the supported orientation in ios 6.0 like below
.h file
#import <UIKit/UIKit.h>
#interface UIPopoverController (UIPopoverController_Orientation)
-(NSUInteger) supportedInterfaceOrientations;
#end
.m file
#import "UIPopoverController+UIPopoverController_Orientation.h"
#implementation UIPopoverController (UIPopoverController_Orientation)
-(NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
#end
Here I use UIInterfaceOrientationMaskLandscape as I only supports landscape orientations ie restrict my app to only landscape mode.
Hope this will help you.
Happy Coding :)

creating universal ios app with iOS4.3 and xcode 4.0

I need to create a Universal iPhone/iPad application using Xcode 4.0.
I start creating universal application, there is common app delegate and separate subclass of this app delegate one for iPhone and iPad. So I override the didFinishLaunchingWithOptions and add a viewcontroller.
But my problem is I can't set the frame of subviews correctly.
[m_objMainTableView setFrame:CGRectMake(40, 330, 365, 700)];
m_objMainTableView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin);
The tableview goes out of superview only a small portion is visible.
But After I comment the autoresizingMask (second line) the tableview displayed in original frame.
I created the same code in older xcode version as an iPad app it works fine.
what I can do?
thanks in advance....