UISplitViewController 在尝试使用其中的 UINavigationController 后停止自动旋转
我在 iPad 应用程序中使用 UISplitViewController 时遇到了一些问题。我正在尝试使用 UISplitView 内部的 UINavigationController 制作一个简单的导航树。我使用了以下基本代码来执行此操作:
NavController.h
@interface NavController : NSObject {
/*
* This is connected properly to the UINavigationController in the
* UISplitViewController through Interface Builder.
*/
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
NavController.m
#import "NavController.h"
@implementation NavController
@synthesize navigationController;
- (void) awakeFromNib {
UIViewController *testController = [[UIViewController alloc] init];
UITableView *tableView = [[UITableView alloc] init];
[testController setView: tableView];
[navigationController pushViewController: testViewController
animated: YES];
}
@end
此代码成功将视图推送到导航控制器,并且我可以使用后退按钮导航回来,但是,我的问题出现了,因为在发生这种情况之后,我的 UISplitViewController 不再自动旋转或根本从纵向位置旋转。当我删除此代码(并且视图不会被推送)时,它会按预期工作。
我做错了什么,我是否以正确的方式处理这件事?
I've been having a bit of trouble with a UISplitViewController in my iPad app. I am attempting to make a simple navigation tree using the UINavigationController inside of the UISplitView. I have used the following basic code to do this:
NavController.h
@interface NavController : NSObject {
/*
* This is connected properly to the UINavigationController in the
* UISplitViewController through Interface Builder.
*/
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
NavController.m
#import "NavController.h"
@implementation NavController
@synthesize navigationController;
- (void) awakeFromNib {
UIViewController *testController = [[UIViewController alloc] init];
UITableView *tableView = [[UITableView alloc] init];
[testController setView: tableView];
[navigationController pushViewController: testViewController
animated: YES];
}
@end
This code successfully pushes the view to the navigation controller, and I can navigate back with the back button, however, my problem arises with the fact that after this happens, my UISplitViewController no longer auto-rotates or rotates at all from the portrait position. When I remove this code (and the view does not get pushed) it works as expected.
What am I doing wrong, and am I going about this in the right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这也让我彻底抓狂。我做了一些事情使它起作用,但我对我的解决方案并不满意 - 1)我不太理解它,2)它看起来很老套。
我将其添加到我的应用程序委托(我的 .m 文件)中:
这在很大程度上有效。对于不自动旋转的视图,我必须使用变换手动旋转视图。我做了类似的事情:
希望这有帮助!如果有人能指出我所犯的错误(或我正在犯的坏事),我会很乐意学习。 :)
This drove me absolutely nuts too. I did a couple of things that made it work, but I'm not happy about my solutions -- 1) I don't really understand it and 2) it seems hacky.
I added this to my app delegate (my .m file):
This worked for the most part. For the views that didn't auto-rotate though, I had to manually rotate the views myself using transforms. I did something like:
Hope this helps! And if someone can point out mistakes I've made (or bad things I'm perpetuating), I'd be happy to learn. :)