Storyboard in Xcode is so slow

8k Views Asked by At

I have 150 UIViewController in Storyboard and scrolling between these Views is so slow. I can't zoom in and zoom out easily and it takes some serious time to do sty.

I'm on MBPR and I installed Xcode 4.4

Spec: 2.3GHz / 16G / 256 which I think it's enough to handle such a thing.

Is there any options, settings, or tips/tricks to have so many views in storyboard and don't miss the performance.

NOTE: I've done all the possible solutions (deleting cache and workspace). Didn't work. It has something to do with number of UIViewController in Storyboard.

Thanks

Update 2016: Just to update this question as there is a new feature in Xcode 7 that allows you to refactor the Storyboard into multiple Storyboards.

Refactoring Storyboards https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/RefactorStoryboard.html

If you search the term "refactoring storyboards" you will find good tutorials :)

4

There are 4 best solutions below

1
On BEST ANSWER

Definitely use multiple storyboards for this. I am not aware of any limitations in using storyboards but trying to render all those UI code at one time is hard for your machine and it is also hard for developers to understand.

Try to logically divine your storyboards into categories such as: "profileSB, feedSB, mapSB, messagesSB, settingsSB"

Here are some good tutorials on the creation of these:
http://spin.atomicobject.com/2014/02/18/ios-storyboards-xcode5/
http://www.skillmasters.net/main/xcode-using-multiple-storyboards/

1
On

150 ViewControllers in one Storyboard sounds awful lot to me. Try to minimize your flow or split into multiple storyboards if you really need so many

8
On

It is considered best practice to split up storyboards into lots of different modules (each one in a separate storyboard). It will take away these performance issues you are having and also has other advantages such as making it easier to manage in general (no massive SVN conflicts etc).

However I had another issue which was causing storyboard lag. I had approx 25 view controller and was receiving ALOT of lag - but only when Xcode was running on an external monitor.

I noticed that if I disabled "auto layout" for the storyboard, the lag would completely disappeared. I reverted this change, and then followed the following process: -Delete a ViewController -test if it still lags -if still laggy revert changes

Eventually I found a certain ViewController which if deleted stopped all lag. I then reverted this and went through the views to see which view caused the lag. I eventually narrowed this down to a "UIButton" inside a "UIBarButtonItem". I believe I changed the "Type" property on the button, and then changed it back and the lag stopped. From SVN it seems like the frame was changed in the .storyboard file. After this point the lag never came back again.

TLDR: Storyboard lag is not always because you have too many items in the storyboard. I managed to get rid of a lag problem by causing Xcode to re-do some layout.

Hope my experience will help someone else diagnose/solve their problems. I was working for about 0.5 years before I finally got really annoyed and tried to solve the issue.

0
On

I had a UIStoryboard with 10 or more UIViewControllers and additional ContainerViews. After layouting the views and customizing more and more, the UIStoryboard got more and more lazy.

My approach was to setup the views inside single UIStoryboards. Loading the controllers is done inside my Menu, where I setup an NSArray with all identifiers for the UIViewController which also have to be setup inside the UIStoryboard:

enter image description here

When loading the menu, I loop through the NSArray and load the UIViewControllers by identifiers from the specific UIStoryboard. This is the place where I needed to implement a switch, for the different UIStoryboards:

self.arrayVCAll = [NSMutableArray new];
for ( NSArray *array in _arrayViewControllerAll ){

    NSMutableArray *arrayTemp = [NSMutableArray new];

    for (UIViewController *vc in array ){
        NSString *strViewController = [NSString stringWithFormat:@"%@", vc];
        UIStoryboard *storyboard;

        if( [strViewController isEqualToString:@"CustomOneStoryboard"] ){
            storyboard = [UIStoryboard storyboardWithName:@"FirstVC" bundle:nil];

        } else if( [strViewController isEqualToString:@"CustomTwoStoryboard"] ){
            storyboard = [UIStoryboard storyboardWithName:@"SecondVC" bundle:nil];

        } else {
            storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        }

        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:strViewController];

        MyNavController *nav = [[MyNavController alloc] initWithRootViewController:controller];
        [arrayTemp addObject:nav];
    }

    [self.arrayVCAll addObject:arrayTemp];
}

In my case, there was just a problem with the segues after separating the initial UINavigationController from my UIViewControllers. The segues won't push to a navigationController, if there is no initial UINavigationController. Thats why I added a UINavigationController on each UIViewController (of my NSArray) so the UIStoryboardSegue will be done correctly. The UINavigationController also doesn't need to be connected to a class, just include it inside the UIStoryboard and connect it to the first UIViewController.