Is this a correct way to create custom controls with support of Interface Builder?
I'd like to create my dialogs using Interface Builder, but splitting them in small components in order to better manage or possibly reuse them.
In Apple documentation is advised that a dialog contains only a view controller derived from UIViewController, using it as root, while the other components that constitute the dialog, if I understand correctly, should be simply views, not view controllers: this is due in order to avoid problems in some situations handled by a view controller, eg. when the form is rotated / resized.
Then only way I found to build this reusable user controls is following this steps:
- add an iPhone View to the project (e.g. MyCustomView)
- edit it in Interface Builder
- then add at least an outlet inside it (in this way MonoDevelop create the class definition in MyCustomView.xib.designer.cs)
- in MyCustomView.xib.cs i defined the other part of the partial class MyCustomView, inheriting from UIView and adding a constructor with the IntPtr parameter
Then, in order to load this reusable view inside the dialog that need it (in this sample could be MainWindow), I added a UIView to MainWindow, and associated an outlet to it (calling it Placeholder).
- Then in MainWindow code (that is, in this case in the main code), I created an istance of MyCustomView using NSBundle.MainBundle.LoadNib("MyCustomView", ...) and getting the view instance from the array returned
- finally, I gave to the MyCustomView instance the size of the Placeholder view, and add it to Placeholder as sub-biew (via Placeholder.AddSubview)
Is this correct, or are there better ways to accomplish this (always using IB... I know of the other approaches based only on code)?