且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS - 在单个屏幕上使用多个视图控制器

更新时间:2022-11-23 09:23:40

在回答你的第一个问题时,如果你确实有几个viewControllers由一个容器viewController管理,为什么会你不是每个viewControllers都是委托到他们的显式函数?因此,从该viewController触发UIAlertView或UIActionSheet的任何按钮操作等都将成为这些特定警报的委托?

In response to your first question, if you are indeed having several viewControllers managed by one container viewController, why would you not have each of those viewControllers be the delegate to their explicit functions? Thus, any button actions etc. that trigger a UIAlertView or UIActionSheet from that viewController would be the delegate to those specific alerts?

你也可以很好地服务于块UIKit类别在那里。名叫Mugunth Kumar的绅士有一个名为UIAlertView + MKBlockAdditions,我发现它非常方便摆脱一堆代表意大利面。

You could also be well served looking into some of the block UIKit categories that are out there. Gentleman named Mugunth Kumar has one called UIAlertView+MKBlockAdditions that I've found very handy for getting rid of a bunch of delegate spaghetti.

通常的做法是定义一个基本的UIViewController所有其他viewControllers都继承自,您实现所有常见的帮助方法。将最小公分母放在那里,并将其余控制器设置为此类的子类。这至少有助于复制和粘贴问题,以及DRY范例。

It's common practice to define a base UIViewController that all of your other viewControllers inherit from, where you implement all the common helper methods. Put the lowest common denominator in there, and set the rest of your controllers to be subclasses of this. That at least helps with copy and paste problems, and the DRY paradigm.

最后,直到iOS5,将viewControllers封装在viewControllers中是很麻烦的,因为旋转方法没有得到在所有子视图中自动调用。工作流程如下:

Finally, until iOS5 it was hacky to encapsulate viewControllers within viewControllers because the rotation methods didn't get invoked in all of the subviews automatically. The workflow goes like this:

[viewControllerContainer addChildViewController:anotherViewController];
[viewControllerContainer.view addSubview:anotherViewController.view];
[anotherViewController didMoveToParentController:viewControllerContainer];

教授掌管谁的操作系统。

That teaches the OS who is in charge of who.