I need to create a class controller to control the behavior of the user view that I created. The standard approach is to subclass the UIViewController, but in my case, I instead decided to subclass the NSObject for essentially three reasons:
- My view should be added as a small submatrix of the main view controller (it will not be displayed using something like presentModalViewController or pushViewController ...), and it does not require any toolbar or navigation control inside it
- Most likely, my controller will not need to be notified about the orientation of the device, because its representation will always be used in portrait format, so I'm not interested in receiving regular rotation messages. willRotateToInterfaceOrientation etc.
- I need this class to be as light as possible to minimize memory consumption. Not subclassing the UIViewController has the advantage of getting a lighter class without a bunch of methods that I will never need to use
The interface of my controller is quite simple, for example:
@interface MyScrollTabBarController : NSObject <MyTabBarViewDelegate> { } @property (nonatomic, readonly) UIView *view; @property (nonatomic, assign) MyScrollTabBarViewState viewState; @property (nonatomic, retain) Location *rootLocation; @property (nonatomic, readonly, retain) Place *place; - (id)initWithPlace:(Place *)aPlace; - (void)setRootLocation:(Location *)location animated:(BOOL)animated; @end
To display its internal view from the parent view controller, I will use something like this:
tabBarController = [[MyScrollTabBarController alloc] initWithPlace:aPlace]; tabBarController.viewState = MyScrollTabBarViewStateXX; tabBarController.view.frame = CGRectMake(...); [self.view addSubview:tabBarController.view];
I would like to know what you think of my choice if you think that it may be flawed and what you usually do when you need to write a controller for a view that is not full-screen like mine.
thanks
source share