0

I am now using my navigation Item to create exit button (left navigation item). When it comes to creating the view controller embed in navigation view controller , it seems that we cannot exit the app by using popViewControllerAnimated and dismissViewControllerAnimated . WOuld you please tell me what to do ?

The below is my code for embed view controller

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    navigationBar =  self.navigationController.navigationBar;

    [navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                           [UIColor whiteColor], NSForegroundColorAttributeName,
                                            [UIFont fontWithName:@"TitilliumText22L-Medium" size:22.0], NSFontAttributeName,
                                            nil] ];



    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"TEST SSS"];

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    [button setImage:[UIImage imageNamed:@"menu_back.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *buttonItemA = [[UIBarButtonItem alloc] initWithCustomView:button];
    navigationItem.leftBarButtonItem = buttonItemA;

    UIButton *buttonA = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 88, 30)];
    [buttonA setImage:[UIImage imageNamed:@"sss.png"] forState:UIControlStateNormal];
    UIBarButtonItem *buttonItemB = [[UIBarButtonItem alloc] initWithCustomView:buttonA];
    navigationItem.rightBarButtonItem = buttonItemB;
    [navigationBar pushNavigationItem:navigationItem animated:NO];

}

- (UIStatusBarStyle) preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)buttonClicked:(id)sender {
    NSLog(@"ssd finish");
    [self.navigationController popViewControllerAnimated:YES|NO];

}

@end
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141
  • 1
    read [this](http://stackoverflow.com/questions/355168/proper-way-to-exit-iphone-application), apple dont recommend manually trigger the exit though, and exit app is not dismissing your root VC – Tj3n Dec 30 '15 at 04:01
  • even if this is the only one root view ? – Jeff Bootsholz Dec 30 '15 at 04:02
  • Yes, dismiss your VC is just dismissing to the black window i think, not terminate the app – Tj3n Dec 30 '15 at 04:03
  • The question of an android dev. Apple not allows exist app programmatically. If you don't care about AppStore, using abort(). – zendobk Dec 30 '15 at 04:44

1 Answers1

1

Please read the document on this link, Apple Q&A Link for quit iOS app

This should answer your question:-

Go to your info.plist and check the key "Application does not run in background" and set it to :- "TRUE" Then the time user presses the home button, the application exits completely.

OR as the link suggests pop an alert so that the user will know what to do for exiting the app.

Arpit Dhamane
  • 503
  • 7
  • 19