creating universal ios app with iOS4.3 and xcode 4.0 - iphone

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....

Related

Xcode5 build universal app for iPhone in iPad store

I found a problem with my build, looks like Xcode5 changed this in comparing to Xcode4.
before, in Xcode4: I choose to build "universal" app and my app with iPhone size is scaled on iPad, can be found both in iPhone and iPad store.
now, in Xcode5: if I choose "universal", my app with iPhone size is no longer scaled on iPad, but keeps the original size while leaving the whole right part empty. If I choose "iPhone", it is scaled on iPad, but can no longer be found in iPad store.
I noticed UIDeviceFamily is removed from Info.plist in Xcode5
what I want is simply the same build result with Xcode5 for my app as with Xcode4. Anyone has any idea about it?
Here's my code to initiate the root view in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
DialoguesVC* dvc = [[DialoguesVC alloc] init];
HomeVC* hvc = [[HomeVC alloc] initWithRootViewController:dvc];
[self.window setRootViewController:hvc];
HomeVC is a UINavigationViewController.
Xcode 5 requires that a separate storyboard for iPhone and iPad is defined in the target for your universal app. You can however select the same one if you like. Here's how to do it:
In the Project Navigator on the left, select the bug blue bar at the top with your Project Name in it.
On the right, select your target from the drop down menu. This is where you define if your app is iPhone, iPad or Universal. In your case, select Universal (under Deployment Info).
You should now see two tabs in the same section: iPhone and iPad. Switch between them to define allowed orientations, Status Bar Style and - most importantly - select which Storyboard you're using for each device.
That should do the trick, and when run on an iPad, it should now load the iPhone storyboard as Xcode 4 would have done.
This may not look as attractive as you would hope - in which case you can copy your iPhone Storyboard and make changes specifically for iPad. I've explained how to do this here: http://pinkstone.co.uk/how-to-convert-your-iphone-storyboard-into-an-ipad-storyboard/

How can I change a UIBarButtonItem's TintColor when building for iOS 6.1 and running under iOS 7?

I have an iOS app compiled using the 6.1 SDK with some UIBarButtonItems where the TintColor is set programmatically in ViewWillAppear.
UIBarButtonItem leftButton = new UIBarButtonItem(...);
leftButton.TintColor = UIColor.FromRGB(231, 231, 231);
Resulting in this.
I've upgraded my iPhone to 7.0 but I still need to build for the 6.1 SDK for backwards device compatibility (business reasons).
When I build the app using the 6.1 SDK and run it on an iPhone running iOS 7.0, the toolbar looks like this.
Having read through the iOS 7 UI Transition Guide, I tried setting the UIWindow's TintColor to see if this had an effect. It did not.
On interesting thing - on this form, when I display an ActionSheet, after the ActionSheet is dismissed, the background of the Cancel and Save buttons changes from "black" to "white". I'm currently investigating why this happens.
If I can't change the TintColor programmatically under iOS 7.0 I'm thinking of creating custom background images for the buttons, like this.
And use SetBackgroundImage to override the existing background.
Thanks in advance.
Update - 09.24.13
poupou's answer pointed me to the WWDC video (link) which gave me the solution at 8:37 - I need to set the navigation bar's TintColor instead of setting the specific button's TintColor.
NavigationBar.TintColor = UIColor.FromRGB(231, 231, 231);
I tried setting the UIWindow's TintColor to see if this had an effect. It did not.
It should - but if you're setting TintColor on some other UI elements then it will have priority over the one set on the main UIWindow.
There's a whole session of WWDC 2013 (session 214) about TintColor and how it works in iOS7 (that's the one with the Tic Tac Toe sample).
If you need to run/exclude some code specific to an iOS version you can do:
if (UIDevice.CurrentDevice.CheckSystemVersion (7,0)) {
// iOS 7.0 and later
} else {
// iOS 6.1 and earlier
}

Scroll view doesn't visible when i am using removeFromSuperview in xcode 5 (ios 6.1 simulator)

I am using xcode 5. when i was run app from xcode 5 for ios 6.1 simulator then scroll view doesn' see. for ios 7.0 simulator .Before it was working. I am using interface builder
You can see in following image.....
In ios 7.0 simulator it is working
In ios 6.1 simulator It is Totally white
![It is totally White][2]
In my scroll view view controller in viewDidLoad method i have write below code
[scrollView removeFromSuperview];
[self.view addSubview:scrollView];
When I comment above code then scrollview is visible For ios 6.1 simulator
![enter image description here][3]
Seriously I dont know what is the actual reason? is that above reason or not. In xcode 4.6 it was working .Also my app is live on appstore . Please help me .
Thanks in advance
Seems that You have issue with memory management or with position/size of scrollView. Try to set breakpoint and check what heppends with Your object.
#Kalpesh its simply because removeFromSuperview doesn't work in iOS 7. So your scrollView was not removed (if you had touched the screen it would have crashed). But [scrollView removeFromSuperView]; removed the scrollView in iOS 6 .

How to enable "AutoLayout" of iOS 6 programmatically?

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.

Adding iPad XIB/VIEW to a "View Based Application" in iOS 4

I've created a View Based Application in XCode4 and trying to do the code and UI design according to the way Apple have intended it to be.
So I designed the UI in the AppNameViewController.xib and it works fine; now I want to enable it as a UNIVERSAL application that runs on iPad as well. I changed the App-Target>>Summary>>Devices from iPhone to Universal and miraculously XCode had automatically created MainWindow-iPad.xib (Apple, very nice...), but since I designed the application first screen on the AppNameViewController.xib and not on the MainWindow.xib when I run the app on iPad Simulator I get this ugly screen where my UI objects size and location is distorted (their size is still set for iPhone so they are all crumbled on the left-top corner of the screen).
In my previous app I used the code appearing below to distinct between the AppNameViewControllerForIPHONE.xib and the AppNameViewControllerForIPAD.xib; It was done from the AppDelegate.m file, but in the new XCode View Based Application template the AppDelegate doesn't go through initWithNibName method at all.
Code I used on XCode 3 that cannot be used on XCode 4:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
viewController = [[AppViewController alloc] initWithNibName:#"AppViewControllerIPAD" bundle:[NSBundle mainBundle]];
}
else {
viewController = [[AppViewController alloc] initWithNibName:#"AppViewControllerIPHONE" bundle:[NSBundle mainBundle]];
}
Long question... still, anyone had any idea how it should be done here? Where should I design the iPad UI or is there a way to easily transform the iPhone xib to an iPad one?
You have to follow the new naming scheme (idiom in Apple-speak) specified for Universal Applications for the NSMainNibFile key in your info.plist. For example, if you set your NSMainNibFile to be "MainWindow-iPhone", the xib for ipad would be "MainWindow-iPad".
The same naming convention should hold for the views in a view based application (I can't test right now, installing new xcode).