如何解决ios 7中的后退键错误?

时间:2014-05-21 06:55:50

标签: iphone ios7 uinavigationcontroller

当我点击后退按钮然后控制器返回菜单但崩溃应用程序?

       -(void)launchselfEvalutionFromPresidentDetailViewController
        {
            Self_Evalution_Page *self_page=[[Self_Evalution_Page alloc]initWithNibName:@"Self_Evalution_Page" bundle:nil];

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

        }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

        self.pageController.dataSource = self;
        [[self.pageController view] setFrame: CGRectMake(0,[topBar bottom] + 5,320,500)];


        SelfEvalutionTableView *selfObj=[self viewControllerAtIndex:0];


        NSArray *viewControllers = [NSArray arrayWithObject:selfObj];

        [self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

        [self addChildViewController:self.pageController];
        [[self view] addSubview:[self.pageController view]];
        [self.pageController didMoveToParentViewController:self];

    }

我使用此代码向前移动。但是我点击后退按钮应用程序崩溃。

2 个答案:

答案 0 :(得分:0)

尝试在后退按钮事件或代码中使用此功能。

[self dismissViewControllerAnimated:YES completion:nil];

希望这有帮助。

答案 1 :(得分:0)

自定义后退按钮操作,请尝试以下代码

 UIImage *buttonImage = [UIImage imageNamed:@"backBtn.png"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:buttonImage forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 25, 25);
    [button addTarget:self action:@selector(GoBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = customBarItem;
    [customBarItem release];

调用此函数

-(IBAction)GoBack
{
    [self.navigationController popViewControllerAnimated:YES];
}