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