Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that's likely your best solution. In iOS, a ViewController takes up all it's available space for it's view. Without a "container" view that you manager yourself, any view controller you put up is going to take up the entire window, covering anything you've displayed. </p> <p>However, there's an alternate approach that may be simpler, depending on your project. </p> <p>You could create a UIView object (your button) in some central place (say, your App Delegate class). That view could have a button that you attach to a method:</p> <pre><code>@implementation AppDelegate - (void) someSetupMethod { UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom]; // setup whatever properties // Now set button to call a method *on this AppDelegate object* ("self"): [b addTarget:self action:@selector(homeButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; // Store the button definition somewhere permanant self.reusableHomeButton = b; } - (void) homeButtonTapped:(id)sender { // do something to pop view controllers back to what you want. } </code></pre> <p>Then, in your view controllers, they could all show the home button when they appear:</p> <pre><code>- (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; [self.view addSubview:appDelegate.reusableHomeButton]; } </code></pre> <p>This takes advantage of an intentional side-effect of <code>[view addSubview:...]</code> which is that if the view is already in some parent, it <em>removes it from that parent</em> first, then adds to the new view. </p> <p>It also takes advantage of the fact that a button can send it's message to <em>any</em> object. It doesn't have to be the ViewController hosing the button's parent view. </p> <p>This causes your button to be "moved" from one displayed view controller's .view to a new one whenever a new controller is presented. </p> <p>Since the button has a target of a the AppDelegate object (and will therefore send it's message to that object), it works "from anywhere" as long as the app delegate object exists to receive the message (which it does as long as your app is running). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload