我的后退按钮无法退出我的应用

时间:2015-12-30 03:55:12

标签: ios uinavigationbar back

我现在使用导航项创建退出按钮(左侧导航项)。当创建嵌入导航视图控制器的视图控制器时,似乎我们无法通过使用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 个答案:

答案 0 :(得分:1)

请阅读此链接Apple Q&A Link for quit iOS app

上的文件

这应该回答你的问题: -

转到info.plist并检查密钥 "应用程序不在后台运行" 并将其设置为: - " TRUE" 然后,当用户按下主页按钮时,应用程序完全退出。

或者,因为链接建议弹出警报,以便用户知道如何退出应用程序。