2

I have an UICollectionViewController into TabBarViewController that works for iOS 6.0 and later ios versions. I would like to know if there is any way to use a different ViewController if a device has elder than iOS 6.0 version. For example, can i use a UITableView for devices that use prior version than iOS 6.0 and UICollection for devices that use iOS 6.0 and posterior versions?

I also tried PSTCollectionView but it has some problems.

I added an image that shows my storyboard. My collection is in TabBarController and i want to change to TableView if a device uses prior to iOS 6.0 .enter image description here

hoya21
  • 893
  • 7
  • 24
  • Please use this http://stackoverflow.com/a/5337804/1091539, its the best answer for this question – Mutawe Dec 04 '13 at 09:20
  • possible duplicate of [Check iPhone iOS Version](http://stackoverflow.com/questions/3339722/check-iphone-ios-version) – Mutawe Dec 04 '13 at 09:21
  • @Mutawe i checked this before post this question. But i do not know the way that i handle different controllers into TabbarViewController according to version. This is what i really want. – hoya21 Dec 04 '13 at 09:27

4 Answers4

4

There is very simple solution to it

For Example In your tabBarControllers index 2 is for CollectionView and on 3 is for TableViewController

simply do all required settings icons names etc in storyboard

now in your ApplicationDidFinishLaunchingWith Options do this

As I assume your tabbarController is rootViewContrller do this

UITabbarController *tabbarController = (UITabBarController *)self.window.rootViewController;
NSMutableArray *arrayControllers = [NSMutableArray arrayWithArray:tabbarController.viewControllers];
if (OlderVersion) {//Check
    [arrayControllers removeObjectAtIndex:2];
}else{
    [arrayControllers removeObjectAtIndex:3];
}
[tabbarController setViewControllers:arrayControllers];
Raheel Sadiq
  • 9,847
  • 6
  • 42
  • 54
  • Thank you Raheel.This will work.So if my tabBarController is not the rootViewController i have to do this in viewWillAppear method? – hoya21 Dec 04 '13 at 10:23
  • dont get the scenario, but if you tabbarController is not the rootViewController then get it by StoryBoard Id, first set the ID in storyBoard in Identity Inspector then UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryBoardName" bundle:nil]; UITabBarController *tabbarController = [storyboard instantiateViewControllerWithIdentifier:@"TabbarControllerStoryBoardId"];// storyboardId – Raheel Sadiq Dec 04 '13 at 10:40
0

Yes, you can do that.

Just get the version of the phone with this:

[[UIDevice currentDevice] systemVersion]

And then, load the right view controller depending on the value.

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • Thanks for the response. I know how to check the version of ios that a device uses but i would like to know how to handle the controllers in storyboard – hoya21 Dec 04 '13 at 09:00
  • 1
    Use performSegue according to the versions – Raheel Sadiq Dec 04 '13 at 09:01
  • My CollectionViewController is connected with another screen in storyboard.Can i design another disconnected ViewController for the elder versions in storyboard and call it somewhere in the code? – hoya21 Dec 04 '13 at 09:04
  • @RaheelSadiq i dont know how to do this cause my collection is in TabBarViewController that it has its own segues. – hoya21 Dec 04 '13 at 09:10
  • @hoya21 I dont know the design of your storyBoard but if you are uncomfortable with segues, then make storyBoard reference to that ViewController and push/present modal as you like. See this, for reference for this http://stackoverflow.com/questions/19700439/unable-to-pushviewcontroller-ios/19700584#19700584 – Raheel Sadiq Dec 04 '13 at 09:40
  • and it doesn't matter if your controller is in tabBar just perform the segue in storyBoard as desired – Raheel Sadiq Dec 04 '13 at 09:44
  • @RaheelSadiq I reedited my question and added an image of my storyboard to see the segue. – hoya21 Dec 04 '13 at 09:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/42479/discussion-between-hoya21-and-raheelsadiq) – hoya21 Dec 04 '13 at 09:58
0

You need to add identifier to your view controller

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
if(versionValue>=7)
{
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"viewControllerIOS7"];
}
else
{
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"viewControllerIOS6"];
}

Hope this help.

Greg
  • 25,317
  • 6
  • 53
  • 62
  • thanks for your time. Can you tell me where i have to use this, cause my ViewController is in TabBarViewController? – hoya21 Dec 04 '13 at 09:15
  • You should use it when you create TabBarViewController, when you add collection view to tab bar. I assume you use storyboard but to make this work you have to refactor the code and you have to do it programatically. – Greg Dec 04 '13 at 09:17
-1

Yes, You can do that with checking following condition for your version.

NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

    float versionValue=[currSysVer floatvalue];

    if(versionValue>=6)
    {
        // do some stuff you want to do here
    }

Hope that helps you.

Manthan
  • 3,856
  • 1
  • 27
  • 58
  • Thanks for your answer @Manthan. Can you help me in which part of the code can i do this cause my UICollectionViewController is in a TabBarViewController? – hoya21 Dec 04 '13 at 09:12
  • The `systemVersion` is a float value !! – Mutawe Dec 04 '13 at 09:15