I’m trying to create a custom UIView that can be displayed at any point in the game. In other words, the UIView is not tied to a specific UIViewController.
Right now my solution is to store a UIViewController* in my custom UIView, set it whenever the UIViewController I’m using changes, and then adding the UIView as a subview of the controller.
I figure there has to be a better, and safer, way of handling this, but I haven’t been able to find anything so far.
Thanks
Make a UIView subclass. File > New File > Objective-C Class > (subclass of ) UIView > Give it a Class Name.
So now you should have something like MyCustomView.h and .m
In the View Controller that you want to display the custom view import the header file
Then simply add it to your current view
You can use Interface Builder to graphically lay out the custom view. Or you can do it programmatically. If you’re going the IB way, create a new file, click on User Interface, and View. Give it the same Class Name i.e. (MyCustomView).
Select the File Owner show the Identity Inspector (option command 3).
For Class, change it from NSObject to MyCustomView.