2015-12-30 205 views
0

我現在使用我的導航項創建退出按鈕(左側導航項)。在創建導航視圖控制器中嵌入的視圖控制器時,似乎我們無法通過使用popViewControllerAnimated和dismissViewControllerAnimated來退出應用程序。請告訴我該怎麼辦?我的後退按鈕無法退出我的應用程序

下面是我的嵌入查看控制器代碼

#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 
+1

閱讀[本](http://stackoverflow.com/questions/355168/proper-way-to-exit-iphone-application),蘋果不建議手動觸發出口雖然,並退出應用程序不會解僱你的根VC – Tj3n

+0

即使這是唯一的一個根視圖? –

+0

是的,解僱你的VC只是解僱黑色的窗口,我認爲,不是終止應用程序 – Tj3n

回答

1

請閱讀文檔此鏈接,Apple Q&A Link for quit iOS app

這應該回答你的問題: -

轉到您的info.plist並檢查密鑰 「應用程序不在後臺運行」 並將其設置爲: - 「真」 然後,用戶按下主頁按鈕時,應用程序完全退出。

或者因爲鏈接建議彈出警告,以便用戶知道如何退出應用程序。

相關問題