Reputation: 253
There are 4 items on MyViewController.xib window:
- File's Owner (of type MyViewController)
- First Responder (of type UIResponder)
- View (of type UIScrollView)
- FloatingView (of type UIView)
Both View
and FloatingView
contain some controls (such as labels and text fields...), and are designed using IB. The FloatingView
must NOT occupy the full screen; and my app functionality requires the FloatingView
to move to a newly tapped location when user taps on the screen.
An instance variable UIView *myFloatingView;
is defined as a property/IBOutlet and synthesized, which is connected to the FloatingView
view on IB.
On viewDidLoad
method, I am adding myFloatingView
to my view controller's view as its subview as:
-(void)viewDidLoad {
[super viewDidLoad];
CGRect myFrame = CGRectMake(50, 50, 150, 150); //initial location
self.myFloatingView.frame = myFrame;
[self.view addSubview:self.myFloatingView];
}
Apple documentation says each UIViews should have a corresponding view controller. However, I am using only one view controller here. I am treating the floating UIView object as a regular control, or say as a panel. I might in future allow user to hide/unhide this floating view.
Is this a good practice, or is there a better way (any example) to do what I am trying to do?
Thank you very much for your help.
Upvotes: 0
Views: 245
Reputation: 15588
What you are doing is fine. In fact, a viewController can often control a whole hierarchy. Also, you said your floatingView was in the same nib as your root view? If so, you can probably make it a subview there, instead of adding as a subview in viewdidLoad.
Upvotes: 1