從一個螢屏導航到另一個螢屏(TabBarController 的實體/子螢屏)時,應用程式崩潰并拋出錯誤。
執行緒 1:“-[UINavigationController selectedIndex]:無法識別的選擇器發送到實體 0x105870800”
UINavigationController *nav_1 = [UIApplication sharedApplication].keyWindow.rootViewController;
UITabBarController *tab = (TabbarController*)[UIApplication sharedApplication].keyWindow.rootViewController;
NSInteger sel_idx = tab.selectedIndex; //App Crashing here with error:- Thread 1: "-[UINavigationController selectedIndex]: unrecognized selector sent to instance 0x105870800"
UINavigationController *nav = [tab.viewControllers objectAtIndex:sel_idx];
- 在使用以下代碼進行螢屏重定向但遇到錯誤之前它作業正常
Multiple Navigation Stack,這導致了不必要的崩潰和應用程式凍結問題
if ((UserDefaults.standard.value(forKey: "isUserSignIn") as? Bool) == true)
{
NSLog("if called tabBarController")
self.window?.rootViewController = storyBoard.instantiateViewController(withIdentifier: "tabBarController")
}
else
{
self.window?.rootViewController = storyBoard.instantiateViewController(withIdentifier: "ProfileNavController")
}
- 現在我已經更改了如下代碼,bcz 我正面臨
Multiple Navigation Stack. 因此,更改為以下代碼后,Multiple Navigation Stack問題已解決,但面臨提到的錯誤
if ((UserDefaults.standard.value(forKey: "isUserSignIn") as? Bool) == true)
{
NSLog("if called tabBarController")
let tabBar = storyBoard.instantiateViewController(withIdentifier: "tabBarController")
nav = UINavigationController(rootViewController: tabBar)
self.window?.rootViewController = nav
}
else
{
NSLog("else called LoginViewController")
let login = storyBoard.instantiateViewController(withIdentifier: "LoginViewController")
nav = UINavigationController(rootViewController: login)
self.window?.rootViewController = nav
}
- 因錯誤而崩潰
![[UINavigationController selectedIndex]:發送到 UITabBarController 實體的無法識別的選擇器](https://img.uj5u.com/2022/06/24/26ea207d17ec430aa1f25bfa9e34a3e5.png)
uj5u.com熱心網友回復:
要在將根更改為您需要的導航后訪問選項卡
UINavigationController *nav_1 = [UIApplication sharedApplication].keyWindow.rootViewController;
UITabBarController *tab = [nav_1.viewControllers objectAtIndex:0]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/495030.html
標籤:IOS 目标-c 导航控制器 uitabbar控制器
