iOS how can I use storyboard elements that don't exist in earlier versions of iOS? - ios7

I have a project originally targeting iOS7 using a storyboard. I've added a UIStackView to a view controller and get an error that "UIStackView before iOS 9.0". The build fails because of this error.
How can I keep my project as iOS7, while conditionally including newer storyboard elements from iOS9 if device supports them?
I already have conditional code in the project that only runs on iOS8+, but how can I do something similar with a storyboard?

The class UIStackView (and its software) is provided by iOS 9, but is not provided by iOS 8 or 7. When the app tries to instantiate an object from the storyboard in iOS 8, it will fail because it cannot find the class.
The only ways around this:
have different storyboards for different iOS vesions
build a custom class that does the same thing. Then you can use it in the older versions of the iOS. You might find open source libraries that already do this for the class you want.

Related

Tabbar icons not showing selected state in ios7

I'm currently in the process of building an app in XCode 4.6 with iOS 6 as the minimum target. As far as I'm aware this app should work in iOS7 devices, however the selected icon stays on my unselected icon when changing tabs. iOS6 devices work absolutely fine
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Home" image:[UIImage imageNamed:#"Tab_home.png"] tag:0];
[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:#"Tab_homeselected"] withFinishedUnselectedImage:[UIImage imageNamed:#"Tab_home.png"]];
Now looking through Apple docs/Stackoverflow I've seen a few posts saying that these methods are deprecated in iOS7 which is fair enough. However I'm not using XCode 5 or building for iOS7. I'm building for iOS6 and as far as I'm aware Apple state that old apps should work.
Does anyone know how I can get around this? I've tried the suggestion here issue with ios7 tabbar controller
but I get build errors as UIImageRenderingModeAlwaysOriginal is not defined. Is it a case of somehow using respondsToSelector and performSelector for this to do something similar to
[[UITabBarItem alloc] initWithTitle:#"Music" image:musicImage selectedImage:musicImageSel];
as outlined at UITabBar not showing selected item images in ios 7
The build errors for UIImageRenderingModeAlwaysOrigina, is because it was only introduced in iOS SDK 7.0 so if you are building for iOS 6 you cannot use this as it is undefined (not included in SDK 6.x), If you are building solely for iOS 6 it will work on iOS 7 devices but you can only use code that is present in the iOS 6 SDK (which you are using). I wouldn't worry about Apple docs/Stackoverflow saying things are depreciated, you only need append your code if your compiler (Xcode) says it's depreciated for your deployment target (in your case 6.x).

iOS / Objective-C : UICollectionView protocol definitions and iOS 5

I've yet to make a Auto-Layoutless Storyboard to running on iOS 5 so my code won't even run on iOS 5 at the moment. However, I do plan on supporting it. At the same time, I also want to incorporate collection views in my app. I will support it on iOS 5 through the use of the publicly available PSTCollectionView on github. I figure, define the collection view IBOutlet as an id and then everything else is simple. Expect one thing...
Defining the delegate and datasource the collection views is a must.
So my question is, upon defining the UICollectionViewDelegate and UICollectionViewDataSource in my view controller
a. will my project even compile for iOS5 devices?
b. if not, how do I add a macro to conditionally define the respect protocols on iOS5 and iOS6?

How to use NSLayoutConstraint in iOS 6?

My app should support both iPhone resolutions (5 and older) using iOS 5 and iOS 6. When I use autolayouts in IB, on iOS 5 app crashes like this: link
So, I am trying to use NSLayoutConstraint in code, but unsuccessfully yet.
Subquestions:
I am adding constraints in viewDidLoad method, but is it correct?
Does updateViewConstraints invoke by framework? I have never seen that it was invoked.
I tried to use examples from apple's docs, but it was without effect to view.
Anybody knows how to do it?
PS: I know it's possible to make it manually by setting frames, but I would like to use NSLayoutConstraints.
UDP: Yes, I know, that's why i use NSLayoutConstraint in code. I can make condition for determining iOS version. The question is about iOS6.
The AutoLayout feature is only compatible with iOS6 and is not supported in iOS5. Thus the crash
If you intend your app to be compatible with iOS5, you can't use AutoLayout in your XIB files.
You can only use older methods, like the AutoResizingMask for example (which is often sufficient for most cases anyway).

iAds throw an error quickly (XCode 4.3.1, iOS5, Storyboard)

Trying to test iAds from XCode 4.3.1. Without thinking much of it, I started using a storyboard, however all the examples of iAds I find use the XIB file only.
http://www.techotopia.com/index.php/Integrating_iAds_into_an_iOS_5_iPhone_App#Displaying_the_Ad
http://www.youtube.com/watch?v=zkMhWPh6fzM
http://www.youtube.com/watch?v=hsjSCM9JJrM
Even the iAds Suite is built on XIB file.
I'm pretty new at ObjectiveC, so I may have overlooked something obvious. But is that normal that using these examples fail onto a storyboard?
I could post code, but honestly that's the same as the YouTube examples.
Add iAd.framework to your target

Why are MKPolyline and MKPolygon working in iOS 3.2.2 (on an iPad)?

As far as I can tell, technically MKPolyline and MKPolygon should not be functional/available when running on an iPad or any other device prior to iOS4. Nevertheless, when I installed 3.2.2, on the device, and updated my build tools with the latest (non-beta) iOS 4.2 SDK, they both work just fine, along with their associated views. What the hell?
I'm not exactly complaining here, given that the alternative would be NVPolyline and it doesn't play well with a huge number of points. I'm just confused. Can someone explain why these classes are available and working on the iPad?
I have not, however, had any success subclassing MKOverlayPathView on 3.2.2, even though MKPolylineView and MKPolygonView both descend from it.
The docs certainly claim that it was first available in 4.0, but I remember the new MapKit overhaul being part of the diff for 3.2. I think the docs just have the timeline of that update wrong.