简体   繁体   English

故事板中的视图过多-Xcode运行缓慢

[英]Too many views in storyboard - Xcode running Slow

I'm helping someone out with an xcode project but it's almost impossible. 我正在帮助某人进行xcode项目,但这几乎是不可能的。 They have around 100 View controllers on their storyboard and it's just running really slow. 他们的故事板上有大约100个View控制器,而且运行速度非常慢。 I've followed all of the guides on making Xcode faster but they just don't help for this situation. 我遵循了所有有关使Xcode更快的指南,但是它们对于这种情况无济于事。 Outside of that storyboard, when we're working in the .h and .m files it runs perfectly fine, it's just inside the storyboard that it runs slow. 在该情节提要之外,当我们在.h和.m文件中工作时,它运行良好,位于情节提要中,运行缓慢。 Has anyone had any experience with a project like this? 有没有人有过这样的项目经验? What did you do? 你做了什么? Or what can I do to make it possible to work in the storyboard? 或者我该怎么做才能在情节提要中工作? Thanks 谢谢

My solution is: Open a new Window from the Storyboard and minimize it. 我的解决方案是:从情节提要中打开一个新窗口并将其最小化。 So it stays in RAM and won't reload. 因此它保留在RAM中,不会重新加载。 Working with the storyboard keeps quick and easy now. 现在,使用情节提要板可以轻松快捷地进行工作。

I faced the same issue when I was working on an Enterprise App. 在开发企业应用程序时,我遇到了同样的问题。 In the Project I had only one storyboard and all views in a single storyboard. 在项目中,我只有一个storyboard ,所有视图都放在一个情节提要中。 Opening the storyboard caused Xcode to get very slow. 打开情节提要导致Xcode变得非常慢。

So I divided the storyboard into multiple storyboards as module-wise and load a separate storyboard per module like in the code below: 因此,我按模块方式将情节提要板分为多个情节提要板,并按以下代码在每个模块中加载一个单独的情节提要板:

If I want to push a view controller: 如果我想推送视图控制器:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboardName" 
                                                     bundle:nil];
UIViewController *viewController = 
 [storyboard instantiateViewControllerWithIdentifier:@"Members_ViewController"];

[self.navigationController pushViewController:viewController animated:YES];

We're having the same issue, and commonly recommended performance tweaks didn't help. 我们遇到了同样的问题,通常推荐的性能调整无济于事。 On a MacBook Pro with SSD I see CPU utilization go to 80-90% when in storyboard view and navigation lag is incredibly frustrating. 在带有SSD的MacBook Pro上,在情节提要视图中,我发现CPU利用率达到80-90%,并且导航滞后非常令人沮丧。 Simulator can take up to a minute to display, and Xcode often won't close, requiring a force quit. 模拟器最多可能需要一分钟才能显示,并且Xcode经常无法关闭,这需要强制退出。

These symptoms all disappear if not viewing the storyboard, or if storyboard is open as source code. 如果不查看情节提要或将情节提要作为源代码打开,这些症状将全部消失。

UPDATE: We split our project up into multiple storyboards, and life is good again - CPU utilization is back to single digits and performance is on par with Xcode 4.6.3. 更新:我们将项目分为多个情节提要,并且生活再次愉快-CPU利用率恢复到个位数,并且性能与Xcode 4.6.3相当。 There is definitely an issue with larger storyboards; 较大的故事板肯定存在问题; the only change made to our code in the process was updating references to the main storyboard to a storyboardWithName call instead. 在此过程中,对我们的代码所做的唯一更改是将对主故事板的引用更新为storyboardWithName调用。

One of the view controllers in our project has a container view, and it appeared that the utilization issue stopped when that controller and its container view were moved to a separate storyboard. 我们项目中的一个视图控制器具有容器视图,并且当该控制器及其容器视图移到单独的情节提要板上时,似乎停止了使用问题。 It may have been a coincidence, and we broke up the rest of the storyboard for consistency, but if I were dealing with this issue again, I'd first move any view controllers with container views to a separate storyboard. 这可能是一个巧合,为了保持一致性,我们分解了故事板的其余部分,但是如果我再次处理此问题,我首先将带有容器视图的所有视图控制器移到单独的故事板。

If you are using Xcode 7, Storyboard References are a quick way to create multiple storyboards and will definitely help this issue. 如果您使用的是Xcode 7,则情节提要引用是创建多个情节提要的快速方法,肯定会解决此问题。 The great side about using Storyboard References is it does not involve any extra code whatsoever! 使用情节提要引用的好处是,它不涉及任何额外的代码! See the stackoverflow link below for a full description on how to set it up. 有关如何设置它的完整说明,请参见下面的stackoverflow链接。

在此处输入图片说明 https://stackoverflow.com/a/30772789/3316842 https://stackoverflow.com/a/30772789/3316842

I'm facing the same problem. 我正面临着同样的问题。 Massively frustrating. 令人沮丧。 My storyboard has only 41 views. 我的情节提要只有41次观看。 And I'm running a Mac Min i7 running at 2.3Ghz. 我正在运行以2.3Ghz运行的Mac Min i7。 With the storyboard open, it takes ages to do very simple tasks like move a UILABEL? 打开故事板后,花很长时间才能完成一些非常简单的任务,例如移动UILABEL? Then, in counterpart view, editing code is like being back on a ZX81. 然后,在对应视图中,编辑代码就像回到ZX81上一样。 It's all very well and good banging "intelligence" into the storyboard, but not at the cost of development efficiency. 在情节提要中很好地敲响“智能”,但不以开发效率为代价。 In so far as storyboard "size" guidelines are concerned, I don't ever remember reading that storyboards have to be split beyond a certain size. 就情节提要的“大小”准则而言,我从未记得阅读过必须将情节提要划分成一定大小以外的内容。 Maybe I need to read more. 也许我需要阅读更多内容。

To make the changes required, ie split the storyboard up, slap some VC's on several storyboards, will require a bit of a faff. 为了进行所需的更改,即拆分情节提要,将一些VC打在几个情节提要上,将需要一些麻烦。 I suppose if that's the new best-practice, fine. 我想如果这是新的最佳做法,那就好。 But I could do with more than conjecture. 但是我可以做的不只是猜测。

I also agree with organizing your views across multiple story boards. 我也同意在多个故事板上组织您的观点。 It becomes very handy when you have a view that is called from several other views. 当您有一个从其他几个视图调用的视图时,它将变得非常方便。 Then the storyboard can become like pasta, unclear. 然后,情节提要可能变得像面食一样,不清楚。 In my case I had a camera view that could be called from several views, I put this on a new storyboard and this works great. 就我而言,我有一个可以从多个视图调用的相机视图,将其放在新的故事板上,效果很好。 Since the camera view was also pointing to the search order view, I had to put the search order view also on a separate storyboard. 由于摄影机视图也指向搜索顺序视图,因此我不得不将搜索顺序视图也放置在单独的情节提要上。 Again my main story board got simpler. 同样,我的主要故事板变得更加简单。

So have a main story board, and separate as much as you can onto separate storyboards. 因此,要有一个主故事板,并尽可能将其分离到单独的故事板上。 I made a general class StoryBoardNavigation where I centralized all functions to call child storyboards. 我做了一个通用的StoryStoryNavigation类,在其中集中了所有功能来调用子情节图板。

Here is an example of this: 这是一个例子:

This function navigates to the storyboard called OrderLookupStoryboard and opens the view in start position. 此功能导航到名为OrderLookupStoryboard的情节提要,并在开始位置打开视图。

+(void) NavigateToOrderLookupFrom:(UIViewController *)vc
{
    UIStoryboard * sb = [UIStoryboard storyboardWithName:@"OrderLookupStoryboard" bundle:nil];
    UIViewController * vcTo = [sb instantiateInitialViewController];

    [UIView transitionWithView:vc.view duration:0.8     options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                    [vc.navigationController pushViewController:vcTo animated:NO];
                }
                completion:NULL];

}

This function passes some parameters to the storyboard. 此函数将一些参数传递到情节提要。

+(void) NavigateToCameraFrom:(UIViewController *)vc WithSelectedZone:(int)selectedZone
{
    UIStoryboard * sb = [UIStoryboard storyboardWithName:@"CameraStoryboard" bundle:nil];
    MediaCapture * vcTo = [sb instantiateInitialViewController];
    vcTo.selectedZone = selectedZone;
    vcTo.zoneSet = YES;
    [UIView transitionWithView:vc.view duration:0.8 options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                    [vc.navigationController pushViewController:vcTo animated:NO];
                }
                completion:NULL];

}

This function opens the view in module transition style: 此函数以模块过渡样式打开视图:

+(void) NavigateToSignatureFrom:(UIViewController *)vc withSignee:(NSString *) Signee
{
   UIStoryboard * sb = [UIStoryboard storyboardWithName:@"SignatureStoryboard" bundle:nil];
   UIViewController * vcTo = [sb instantiateInitialViewController];

   ((SignatureVC *) vcTo).Signee = Signee;

   [vcTo setModalTransitionStyle:UIModalTransitionStylePartialCurl];
   [vc presentViewController:vcTo animated:YES completion:nil];
}

I wanted to add that I was having a problem with my storyboard responding slowly when utilizing a container view with a navigation controller inside it. 我想补充一点,当使用带有导航控制器的容器视图时,情节提要板响应缓慢,我遇到了问题。 I even tried putting it in its own storyboard and it still was so slow i was unable to even use it. 我什至尝试将其放在自己的情节提要中,但它仍然是如此缓慢,以至于我什至无法使用它。 It seems that the when container view was resizes the navigation controller, the navigation bar was causing the issue. 似乎当容器视图调整导航控制器的大小时,导航栏引起了问题。

I was able to work around this problem by selecting the navigation controller in the storyboard, hiding the navigation bar by unchecking "shows navigation bar" in the attributes inspector and using "isNavigationBarHidden = false" in either viewDidLoad or viewWillAppear of my view controller class. 通过选择情节提要中的导航控制器,通过取消选中属性检查器中的“显示导航栏”并在我的视图控制器类的viewDidLoad或viewWillAppear中使用“ isNavigationBarHidden = false”,可以隐藏导航栏,从而可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM