久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何獲取根視圖控制器?

How to get root view controller?(如何獲取根視圖控制器?)
本文介紹了如何獲取根視圖控制器?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我需要一個根視圖控制器的實例.

I need an instance of root view controller.

我嘗試了這些方法:

UIViewController *rootViewController = (UIViewController*)[[[UIApplication sharedApplication] keyWindow] rootViewController];

返回:null:

當(dāng)我嘗試獲取控制器數(shù)組時:

Also when I try to get an array of controllers:

NSArray *viewControllers = self.navigationController.viewControllers;

它只返回一個控制器,但它不是我的根視圖控制器.

It returns only one controller, but it isn't my root view controller.

如果我嘗試從導(dǎo)航控制器中獲取:

If I try to take from navigation controller:

UIViewController *root = (UIViewController*)[self.navigationController.viewControllers objectAtIndex:0];

返回:null:

任何想法為什么?我還能嘗試獲取根視圖控制器的實例嗎?

Any ideas why? What else could I try to get an instance of my root view controller?

謝謝.

推薦答案

如果您嘗試訪問您在 appDelegate 中設(shè)置的 rootViewController.試試這個:

if you are trying to access the rootViewController you set in your appDelegate. try this:

Objective-C

YourViewController *rootController = (YourViewController*)[[(YourAppDelegate*)
                                   [[UIApplication sharedApplication]delegate] window] rootViewController];

斯威夫特

let appDelegate  = UIApplication.sharedApplication().delegate as AppDelegate
let viewController = appDelegate.window!.rootViewController as YourViewController

斯威夫特 3

let appDelegate  = UIApplication.shared.delegate as! AppDelegate
let viewController = appDelegate.window!.rootViewController as! YourViewController

斯威夫特 4 &4.2

let viewController = UIApplication.shared.keyWindow!.rootViewController as! YourViewController

斯威夫特 5 &5.1 &5.2

let viewController = UIApplication.shared.windows.first!.rootViewController as! YourViewController

這篇關(guān)于如何獲取根視圖控制器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應(yīng)用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標(biāo)成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中從 CIImage 創(chuàng)建 UIImage 時遇到問題)
主站蜘蛛池模板: 国产亚洲一区二区三区在线观看 | 欧美中文字幕一区二区 | 国产成人在线视频播放 | 欧美在线日韩 | 国产一区二区三区在线免费观看 | 国产精品亚洲欧美日韩一区在线 | 毛片一区二区三区 | 韩国毛片一区二区三区 | 亚洲视频在线看 | 午夜天堂精品久久久久 | 男女下面一进一出网站 | 99国产在线 | 狠狠艹| 久久99深爱久久99精品 | 日韩三级| 日韩欧美一区二区三区免费看 | 国产精品成人品 | 久久免费精品视频 | 男女网站免费观看 | 久久久久久av | 久久国产综合 | av片免费 | 国产美女自拍视频 | 国产精品一区二区三区久久 | 午夜精品一区 | 国产一级视频 | 91性高湖久久久久久久久_久久99 | 黄色片视频 | 久久久天天| 免费a级毛片在线播放 | 亚洲电影第三页 | 久草福利 | 亚洲精品欧美 | 久久久久亚洲精品国产 | 亚洲精品久久久一区二区三区 | 亚洲精品一区二区冲田杏梨 | 国产高清精品一区 | 国产精品综合久久 | 亚洲精品视频免费 | 欧美a在线 | 国产欧美一区二区三区在线看 |