Jul*_*anB 0 iphone xcode uitabbarcontroller autorotate
诺比如此忍受我.
我一直在关注O'Rielyy学习iPhone编程和各种线程来构建我的第一个iPhone应用程序.到目前为止一切都那么好,但项目结束的最后绊脚石是让App自动旋转(仅使用uiwebviews的beta因不自动旋转而被拒绝)
我有邮件App委托,它添加了一个UITabBarController
// myNewsUKDelegate.h
@interface myNewsUKDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
// myNewsUKDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
tabBarController有.h和.m文件 - 我在IB中添加了所有UINavigationControllers,后者又添加了一个UITableView
请参阅http://flatearth.co.uk/nib.png上的图片(也是noob,在问题中发布图片!)
从我的阅读中我明白问题是我添加到主视图的UITabBarController需要'子类'并添加了这个代码.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
下一个视图down/in/subclassed(无论正确的术语是什么),其中包含.h和.m文件的是FirstViewController,它添加了表视图,这已经设置了shouldAutorotateToInterfaceOrientation.
@interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
UITableView *tableView;
NSArray *userList;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) NSArray *userList;
@end
@implementation FirstViewController
@synthesize tableView;
- (void)viewDidLoad {
[super viewDidLoad];
// I tried adding
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// lots of other code ; )
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
所以问题似乎是[self.window addSubview:tabBarController.view]; 添加标签栏,它不会添加返回YES位的shouldAutorotateToInterfaceOrientation.
看来我需要添加一个tabBarController子类,其中包含shouldAutorotateToInterfaceOrientation.所以我按照互联网上的建议阅读并尝试了这个...
// tabBarController.h
#import <UIKit/UIKit.h>
@interface tabBarController : UITabBarController {
}
@end
// tabBarController.m
#import "tabBarController.h"
@implementation tabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
Run Code Online (Sandbox Code Playgroud)
并添加
#import "tabBarController.h"
Run Code Online (Sandbox Code Playgroud)
到myNewsUKDelegate.m
但是失败的是"错误:访问未知'视图'类方法"
[self.window addSubview:tabBarController.view];
Run Code Online (Sandbox Code Playgroud)
myNewsUKDelegate.m中的一行
进一步搜索没有产生任何帮助,我最近的Xcode知识现在已经枯竭了:(任何帮助表示赞赏.
从我的阅读中我明白问题是我添加到主视图的UITabBarController需要'子类'并添加了这个代码.
不,你不需要这样做.标签栏控制器通过询问所有子控制器是否支持此方向来确定它是否支持特定的接口方向.在您的情况下,这些似乎是导航控制器,它们会询问当前的子控制器是否支持方向.
换句话说,您必须确保所有自定义视图控制器都返回YES所需的界面方向.