Storyboard in Xcode is so slow
Asked Answered
E

4

12

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 :)

Essentialism answered 27/7, 2012 at 16:29 Comment(2)
Have you already solved your problem? Maybe you can mark the correct answerHemelytron
oh my bro !!, 150 vc, feeling the pain :-sOxytocic
P
6

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/

Poly answered 30/10, 2014 at 11:48 Comment(1)
To complete this answer in a newer version of Xcode, Refactoring Storyboards developer.apple.com/library/ios/recipes/…Essentialism
H
7

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.

Halfcaste answered 17/8, 2015 at 14:54 Comment(8)
Bingo! I had unbelievable slowness and my storyboard has only 7 view controllers. Two of the VCs had a UIButton in a BarButtonItem. I deleted those buttons and instant speed. Now I know the cause, on to finding a solution...Lopsided
Hey @Swany, as I said in my post I kind of removed them and re-added them and it reset the frames which stopped the insane lag. Try re-adding them it might work for you.Halfcaste
@RufusMall re-adding the buttons didn't work for me. Since I am in a bit of a time crunch I am now adding them in code and everything is happy. I will revisit when time permits.Lopsided
Ok, please let me know if you do find a solution to get it working perfectly. I also did some "switching around" of the button styles etc so maybe it was actually that which solved it. I just remember that the .Storyboard source looked exactly the same in SVN, just with different readings for the frame. Good luck.Halfcaste
I seem to be having the lag when on the external monitor. Moved off the external monitor, no lag.Harbourage
Yep, having lag on the external monitor only.Potheen
Thank you for the external monitor tip! I spent hours trying to find out why my storyboard suddenly was unusable, and it was because I moved the XCode window to another monitor.Pteridophyte
Ha no problem! I really find it really strange. Maybe someone should open a Radar ticket with apple to get it sorted. Surprised the issue is still around.Halfcaste
P
6

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/

Poly answered 30/10, 2014 at 11:48 Comment(1)
To complete this answer in a newer version of Xcode, Refactoring Storyboards developer.apple.com/library/ios/recipes/…Essentialism
L
3

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

Leukocyte answered 13/8, 2012 at 7:14 Comment(1)
Hi mate, sounds awful but is there any limitation in using Storyboard? The thing is that there is nothing about how many views can be in Storyboard. I read them all and there weren't any. I tried to reduce them and display content dynamically but it's not for me the client did it before and I just doing some major upgrading. I just asked out of curiosity to see if there is any tips/tricks around or even a limitation. Thanks for reply. And didn't think about the splitting to two Storyboards. Thanks.Essentialism
H
1

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.

Hemelytron answered 26/3, 2015 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.