MonoTouch 中具有多个视图的单个 ViewController
我有一个 iPad 应用程序,它有一个主 ViewController 及其主视图,但我有许多覆盖层(作为单独的视图实现)。我希望所有这些视图都由主视图控制器控制/拥有。
覆盖视图集被打包到单个 XIB 中(仅用于 IB 设计目的,无代码隐藏),并从主视图控制器手动加载,并为每个视图转换为适当的 View 类,作为单独的 .cs 文件实现每个。
一切工作正常,但因为在视图 XIB 中,所有者被设置为主 ViewController 类(为了生成事件、插座的设计器代码),它还为主视图控制器类生成一个 Register 属性,该属性与主视图控制器 XIB 设计器文件中已生成相同的寄存器属性。
我的问题是:有没有办法阻止 MonoTouch/IB 自动生成视图 XIB 的 Register 属性?
谢谢, 佩德罗
我正在使用 XCode/IB 3.2.6、MonoTouch 4.0.5、MonoDevelop 2.4.2、MonoFramework 2.10.4
I have an iPad application that has a main ViewController and its main view as usual, but I have a number of overlays (implemented as separate views). I want all of these views to be controlled/owned by the main view controller.
The set of overlay views are packed into a single XIB (only for IB designing purpose, no code behind) and are loaded manually from the main view controller and casted to the appropriate View class for each of them, implemented as separate .cs file for each.
Everything works fine, but because in the views XIB the owner is set to the main ViewController class (in order to generate the designer code for the events, outlets) it also generates a Register attribute for the main view controller class, which colides with the same register attribute already generated in the main view controller XIB designer file.
My question is: Is there a way to prevent MonoTouch/IB from auto-generating the Register attribute for the views XIB?
Thanks,
Pedro
I'm using XCode/IB 3.2.6, MonoTouch 4.0.5, MonoDevelop 2.4.2, MonoFramework 2.10.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我实现了一个解决方案,它满足了我之前的要求,但有一些缺点,可能适合某些场景,但对于其他场景来说不是一个好的设计模式。
我在 XIB/代码隐藏中实现了主视图控制器,并将其命名为 MainBaseViewController。它只有最少的 UI 元素,因为它主要是所有其他视图的视觉容器。然后,我在一个名为 MainViewController 的单独 .cs 文件中创建了一个类(继承自 (MainBaseViewController),它是一个部分类,以便连接到视图 XIB 生成的设计器代码。该类将保存视图控制器的所有逻辑唯一的缺点是 MainBaseViewController 中的任何 UI 元素(出口)都将由 MonoTouch 生成为私有,我需要在类实现中创建一些受保护的访问器,但没关系,因为它只是视图出口(但这如果基础 XIB 有许多控件,则可能会出现问题)。
恢复:
MainBaseViewController 类和 XIB 将为任何出口提供受保护的访问器,而仅为应用程序中的其他视图提供基本 UI 容器。
MainViewController 是一个 .cs 文件,并且是继承自 MainBaseViewController 的分部类。视图控制器的所有逻辑(管理所有其他视图)
视图存储在 MainViews XIB 中(没有隐藏代码),视图的文件所有者是 MainViewController 类,它生成可从 MainViewController 类访问的所有出口和事件。
单独的 .cs 文件实现视图 XIB 中包含的每个视图的每个特定逻辑,这些逻辑是在主控制器从视图 XIB 动态加载视图时创建的。
单独的
该解决方案允许将视图存储在单独的文件中,将视图控制器逻辑存储在另一个文件中(除了 UI)以及特定视图逻辑 sepa
还有其他解决方案或更好的设计模式吗?另一个更简单的选择是将所有视图粘贴在主控制器 XIb 内,从而失去控制器和视图的独立性。
谢谢,佩德罗
Ok, I implemented a solution, it meets my previous requirements but has a few disadvantages, may be suitable for some scenarios and not a good design pattern for others.
I implemented my main view controller in a XIB/code behind and called it MainBaseViewController. It has only the minimum UI elements, because it will mainly be a visual container for all the other views. Then I created a class in a separate .cs file called MainViewController (inherited from (MainBaseViewController), which is a partial class in order to connect to the designer code generated by the views XIB. This class will hold all the logic of the view controller. The only drawback is that any UI elements (outlets) in the MainBaseViewController will be generated as private by MonoTouch and I needed to create some protected accessors in the class implementation, but its ok because it is only the view outlet (but this could be a problem if the base XIB had many controls).
Resuming:
The MainBaseViewController class and XIB will have protected accessors for any outlets and only the basic UI container for the other views in the application.
The MainViewController is a .cs file and is a partial class that inherits from MainBaseViewController, implements all the logic of the view controller (manages all other views)
The views are stored in the MainViews XIB (which has no code behind) and the file owner of the views is the class MainViewController, which generates all outlets and events accessible from the MainViewController class.
Separate .cs files implement each specific logic for each view contained in the views XIB and which is created when the main controller loads the views dynamically from the views XIB.
This solution allows to store the views in a separate file, the view controller logic in another one (apart from the UI) and specific view logic sepa
Any other solutions or a better design pattern? Another simpler option would be to just stick all views inside the main controller XIb, losing the independence of the controller and the views.
Thanks, Pedro