Noobie非常耐心。分类? UITabBarController不会自动旋转
我一直在关注O'Rielyy学习iPhone编程和这里的各种线程来构建我的第一个iPhone应用程序。到目前为止好,但在项目结束时的最终绊脚石是越来越应用到自动旋转(测试版仅使用UIWebViews中被否决不自动旋转)
我的邮件应用程序的委托,还增加了一个的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;
}
有用于tabBarController h和.m文件 - 我加入IB所有UINavigationControllers,这反过来又增加一个UITableView
查看图像在http://flatearth.co.uk/nib.png(太小白张贴在问题的图像!)
从我的阅读我明白,问题是我添加到主视图的UITabBarController需要'subclassed'并添加了此代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
下一个视图下/中/子类(无论正确的术语),它的.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;
}
所以,问题似乎是,当[self.window addSubview:tabBarController.view];添加标签栏它不添加shouldAutorotateToInterfaceOrientation返回YES位。
看来我需要添加一个tabBarController子类,其中包含shouldAutorotateToInterfaceOrientation。所以,我读了,并试图此,在interwebs的建议......
// tabBarController.h
#import <UIKit/UIKit.h>
@interface tabBarController : UITabBarController {
}
@end
// tabBarController.m
#import "tabBarController.h"
@implementation tabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
并添加
#import "tabBarController.h"
到myNewsUKDelegate.m
但是失败“错误:访问未知“视图”类方法”在myNewsUKDelegate.m
的[self.window addSubview:tabBarController.view];
线
进一步的搜索没有产生任何帮助,我最近的Xcode知识已经干了:(任何帮助表示赞赏。
Arrrggghhh!你是对的。我错过了*一个*观点。谢谢你的头。 – JulianB 2011-05-11 20:31:29