在呈现两个视图控制器之后,它不会忽略ios 6中的根视图

时间:2013-05-01 06:23:36

标签: iphone ios6 uinavigationcontroller

这就是我创建了一个继承UINavigationController

的自定义类

CustomNavigationController.h

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController <UINavigationControllerDelegate>

@end

CustomNavigationController.m

#import "CustomNavigationController.h"

@interface CustomNavigationController ()

@end

@implementation CustomNavigationController

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}


@end

父视图控制器

- (IBAction)btnSelected:(id)sender
{
    FirstVC_New *firstVCOBJ = [[FirstVC_New alloc] initWithNibName:@"FirstVC_New" bundle:nil];

    CustomNavigationController *navController = [[CustomNavigationController alloc]initWithRootViewController:firstVCOBJ];
    navController.navigationBarHidden = YES;
    [self.navigationController presentModalViewController:navController animated:NO];
}

在按钮上单击我将呈现新的UIViewController。 这是我为FirstVC_New做的代码。

#pragma mark - Orientation methods.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

- (IBAction)btnNextSelected:(id)sender
{
    SecondVC *secondVCOBJ = [[CouponDetailVC alloc]initWithNibName:@"CouponDetailVC" bundle:nil];

    CustomNavigationController *navController = [[CustomNavigationController alloc]initWithRootViewController:couponDetailVCOBJ];
    navController.navigationBarHidden = YES;

    [self.navigationController presentModalViewController:navController animated:NO];
}

我在SecondVC中完成的这段代码。

#pragma mark - Orientation methods.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);

}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortraitUpsideDown;
}

现在两个观点的呈现都非常有效。主要问题是我无法通过

转到SecondVC的主根视图

以这种方式

[self.parentViewController dismissModalViewControllerAnimated:NO];

或者这样

[self dismissModalViewControllerAnimated:NO];

建议我解决这个问题的合适方法,如何通过iOS 6解决。

1 个答案:

答案 0 :(得分:2)

试试这个方法

[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];

我希望它能为您工作并导航到root视图控制器。