I think that is probably your best decision. In iOS, the ViewController takes up all the free space for viewing. Without a container view that you control yourself, any view controller that you install will occupy the entire window, covering everything that you displayed.
However, there is an alternative approach that could be simpler, depending on your project.
You can create a UIView object (your button) in some central place (say, your application delegate class). There may be a button in this view that you attach to the method:
@implementation AppDelegate - (void) someSetupMethod { UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom];
Then, in your view controllers, they can show the home button when they appear:
- (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; [self.view addSubview:appDelegate.reusableHomeButton]; }
This uses the intentional side effect of [view addSubview:...] , which is that if the view is already in some parent, it first removes it from that parent and then adds it to the new view.
It also exploits the fact that a button can send a message to any object. It should not be a ViewController that will close the parent view of the button.
This causes your button to "move" from one displayed .view view controller to a new one when a new controller is introduced.
Since the button has the purpose of the AppDelegate object (and therefore sends this message to this object), it works "from anywhere" if there is an application delegation object to receive the message (which it has been doing for as long as your application has been running).
source share