【问题标题】:After presenting two viewcontrollers it is not dismissing to the root view in ios 6呈现两个视图控制器后,它不会在 ios 6 中消失到根视图
【发布时间】:2013-04-25 04:29:26
【问题描述】:

这就是我创建的一个继承 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 解决。

【问题讨论】:

    标签: iphone ios6 uinavigationcontroller


    【解决方案1】:

    试试这个方法

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

    我希望它对你有用并将你导航到根视图控制器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多