【发布时间】: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