IPhone back navigation button

I'm having problems with the back button, which doesnโ€™t appear in the PreferencesView window. The navigation bar is displayed when the image is pressed, but there is no return button.

I create this inside a view controller that is not a navigation controller. Any ideas or suggestions as to what is actually happening here.

- (void)viewDidLoad { self.title = @"Settings"; } - (IBAction)showSettingsModal:(id)sender { SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil]; UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:settingsViewController] autorelease]; [self presentModalViewController:navController animated:YES]; [settingsViewController release]; } 
0
source share
4 answers

A new navigation stack is created. You will need to add your own back button and set the action of this delegate method on the calling VC to reject it.

UPDATE: There seems to be a lot of confusion about where and how to reject ModalViewControllers. In most cases, the wrong thing is to call the Dismiss method from the modal VC itself if you want the parent to act on this dismissal. Use delegation instead. Here is a simple example:

ModalViewController.h:

 @protocol ModalViewControllerDelegate -(void)dismissMyModalVC; @end @interface ModalViewController : UIViewController { id < ModalViewControllerDelegate > delegate; } @property (nonatomic, retain) id < ModalViewControllerDelegate > delegate; // The rest of your class properties, methods here 

ModalViewController.m

 @synthesize delegate; 

...

 // Put in the Method you will be calling from that Back button you created [delegate dismissMyModalVC]; 

CallingViewController.h:

 #import "ModalViewController.h" @interface CallingViewController : UIViewController <ModalViewControllerDelegate> // Rest of class here 

CallingViewController.m:

 ModalViewController *mvc = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil]; mvc.delegate = self [self presentModalViewController:mvc animated:YES]; 

...

 // The ModalViewController delegate method -(void)dismissMyModalVC { // Dismiss the ModalViewController that we instantiated earlier [self dismissModalViewControllerAnimated:YES]; 

Thus, the VC receives a proper deviation from the controller that created it. This delegate method can be modified to traverse objects (for example, when you finish user logging, etc.)

+3
source

SettingsViewController does not have a back button because it is located at the bottom of the stack. If you want the button to reject the modal dialog, you will have to add it yourself.

+1
source

you can try this

 UIBarButtonItem * backButton = [[UIBarButtonItem alloc]initWithTitle:@"Back"style:UIBarButtonItemStylePlain target:self.navigationItem.backBarButtonItem action:@selector(dismissModalViewControllerAnimated:)]; 
+1
source

You are introducing your new controller as a modal controller. The modal controller is the topmost one. You must:

  [self.navigationController pushViewController:navController animated:YES]; 

to push the view controller onto the stack, and then you will see the back button.

Read the Apple documentation on the presentation of view controllers: https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

EDIT I did not see the call controller not being part of the navigation controller. In this case, you will need to create a return button manually and set it as a navigation element in the left column.

0
source

Source: https://habr.com/ru/post/909995/


All Articles