![](/img/trans.png)
[英]Replacing UINavigationController With A UIViewController in MainWindows.xib
[英]Create UINavigationController in other xib?
您好,我的AppDelegate
包含以下代碼:
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
現在,我想創建一個XIB
文件,在其中放置一個UINavigationController
並添加一個UITableView
。 如何通過代碼創建此代碼而不更改委托類?
我已經嘗試過了,但是沒有用:
PlacesTableViewController *obj = [[PlacesTableViewController alloc]init];
obj.title = @"Farmacie intorno a te";
UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:obj];
[self.window addSubview:navC.view];
首先,設置窗口的“現代”方法是使用窗口的rootViewController
屬性:
window.rootViewController = someViewController;
舊的方法(將視圖控制器的視圖作為子視圖添加到窗口中)仍然有效,但是應用程序會記錄有關在應用程序啟動時希望設置根視圖控制器的投訴。
其次,如果要使用舊樣式替換根視圖控制器(在這種情況下,您要用viewController
替換navC
),則需要從窗口中刪除舊視圖控制器的視圖。 最好的選擇是僅使用窗口的rootViewController
屬性,因為您的代碼無論如何都會使用該屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.