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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18710757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:46:24  来源:igfitidea点击:

Too many views in storyboard - Xcode running Slow

iosxcodeperformancestoryboard

提问by BrownEye

I'm helping someone out with an xcode project but it's almost impossible. They have around 100 View controllers on their storyboard and it's just running really slow. I've followed all of the guides on making Xcode faster but they just don't help for this situation. 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. 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

我正在帮助某人完成 xcode 项目,但这几乎是不可能的。他们的故事板上有大约 100 个视图控制器,而且运行速度非常慢。我已经遵循了使 Xcode 更快的所有指南,但它们对这种情况无济于事。在故事板之外,当我们在 .h 和 .m 文件中工作时,它运行得非常好,只是在故事板内部,它运行缓慢。有没有人有过这样的项目的经验?你做了什么?或者我该怎么做才能在故事板中工作?谢谢

回答by redestructa

My solution is: Open a new Window from the Storyboard and minimize it. So it stays in RAM and won't reload. Working with the storyboard keeps quick and easy now.

我的解决方案是:从故事板打开一个新窗口并将其最小化。所以它留在内存中,不会重新加载。现在使用情节提要保持快速和轻松。

回答by Nitin Gohel

I faced the same issue when I was working on an Enterprise App. In the Project I had only one storyboardand all views in a single storyboard. Opening the storyboard caused Xcode to get very slow.

我在开发企业应用程序时遇到了同样的问题。在项目中,我storyboard在一个故事板中只有一个和所有视图。打开故事板导致 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];

回答by Craig LaHote

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. Simulator can take up to a minute to display, and Xcode often won't close, requiring a force quit.

我们遇到了同样的问题,通常推荐的性能调整无济于事。在带有 SSD 的 MacBook Pro 上,我看到在故事板视图中 CPU 利用率达到 80-90%,导航延迟令人难以置信。模拟器最多可能需要一分钟才能显示,并且 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. 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.

更新:我们将我们的项目分成多个故事板,生活又恢复了——CPU 利用率回到了个位数,性能与 Xcode 4.6.3 相当。较大的故事板肯定存在问题;在此过程中对我们的代码所做的唯一更改是将主故事板的引用更新为 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.

我们项目中的一个视图控制器有一个容器视图,当该控制器及其容器视图移动到单独的故事板时,利用率问题似乎停止了。这可能是巧合,为了一致性,我们拆分了故事板的其余部分,但是如果我再次处理这个问题,我会首先将任何带有容器视图的视图控制器移动到一个单独的故事板。

回答by baskInEminence

If you are using Xcode 7, Storyboard References are a quick way to create multiple storyboards and will definitely help this issue. 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.

如果您使用的是 Xcode 7,Storyboard References 是创建多个故事板的快捷方式,肯定会帮助解决这个问题。使用 Storyboard References 的好处是它不涉及任何额外的代码!有关如何设置它的完整说明,请参阅下面的 stackoverflow 链接。

enter image description herehttps://stackoverflow.com/a/30772789/3316842

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

回答by Carl Hine

I'm facing the same problem. Massively frustrating. My storyboard has only 41 views. And I'm running a Mac Min i7 running at 2.3Ghz. With the storyboard open, it takes ages to do very simple tasks like move a UILABEL? Then, in counterpart view, editing code is like being back on a 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.

我面临同样的问题。非常令人沮丧。我的故事板只有 41 次观看。我正在运行以 2.3Ghz 运行的 Mac Min i7。故事板打开后,执行非常简单的任务(例如移动 UILABEL)需要很长时间?然后,在对应视图中,编辑代码就像回到 ZX81 上。将“智能”融入故事板非常好,但不会以开发效率为代价。就故事板“大小”指南而言,我不记得读过故事板必须拆分超过特定大小。也许我需要阅读更多。

To make the changes required, i.e. split the storyboard up, slap some VC's on several storyboards, will require a bit of a faff. I suppose if that's the new best-practice, fine. But I could do with more than conjecture.

要进行所需的更改,即拆分情节提要,将一些 VC 放在几个情节提要上,将需要一些麻烦。我想如果这是新的最佳实践,那很好。但我可以做的不仅仅是猜测。

回答by Mark

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.

因此,要有一个主故事板,并尽可能将其分离到单独的故事板中。我创建了一个通用类 StoryBoardNavigation,在那里我集中了所有功能来调用子故事板。

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];
}

回答by Christopher Papa

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”来隐藏导航栏。