問題描述
我有這個問題,但是我在這個論壇或一般互聯網上找不到的信息似乎都無法幫助我.
I have this problem, however none of the information I can find on this forum or the internet in general seems to be able to help me.
似乎有兩個地方會出現此錯誤:
There seem to be two places where this error can come about:
- main.m - 我的函數如下所示:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
UIApplicationMain
中的最后一個參數返回我的 AppDelegate
類的 NSString
值.因此,這工作正常.
The last argument in UIApplicationMain
returns an NSString
value of the class of my AppDelegate
. This is therefore working fine.
2.AppDelegate.m - 有一種舊"的方式來設置根視圖控制器,如下所示:
2.AppDelegate.m - there is an "older" way of setting the root view controller which is like this:
[self.window addSubview:rootViewController];
但是,在我的應用中,它已經更新為:
However, in my app it has already been updated to:
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
因此,互聯網上的當前信息均無效.這有點令人費解,因為我的同事可以讓它在他的計算機上完美運行 - 他是向我發送應用程序源代碼的人,因此所有設置和代碼應該完全相同.
So none of the current information on the internet works. It is slightly more puzzling as my colleague can get it to work on his computer perfectly fine - he was the one that sent me the app source code so all the settings and code should be exactly the same.
我正在嘗試在模擬器中啟動它.它是針對 iOS 5 構建的,但我正在嘗試在 iOS 6.0 模擬器上運行它.
I am trying to launch this in the simulator. It is built against iOS 5, but I'm trying to run it on the iOS 6.0 simulator.
我有最新的 XCode (4.5.1).
I have the latest XCode (4.5.1).
有什么原因會發生這種情況嗎?我該如何糾正它?
Is there any reason this would be happening? And how can I rectify it?
非常感謝
湯姆
推薦答案
我在嘗試將 UITableView 添加到單視圖應用程序時遇到了完全相同的事情.相反,創建一個默認的 Master-Detail Application 項目(file->new->target->...)并查看 AppDelegate 的 didFinishLaunchingWithOptions 實現:
I ran into exactly the same thing trying to add a UITableView to a single-view app. Instead, create a default Master-Detail Application project (file->new->target->...) and see the AppDelegate's implementation of didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MDMasterViewController *masterViewController = [[MDMasterViewController alloc] initWithNibName:@"MDMasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
與其直接將視圖控制器設置為窗口的 rootViewController,不如為 initWithRootViewController 創建一個使用視圖控制器初始化的導航控制器,然后將該導航控制器設置為窗口的 rootViewController.(請注意,您還必須將導航控制器隱藏在屬性中,以免被破壞).
Rather than directly setting your view controller as the window's rootViewController, you need to create a navigation controller init'ed with your view controller for initWithRootViewController, then set that nav controller as the window's rootViewController. (Notice you also have to squirrel away that nav controller in a property so it doesn't get destructed).
這篇關于應用程序窗口應該在應用程序啟動結束時有一個根視圖控制器 - 即使所有已知問題都已修復的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!