简体   繁体   中英

Why does InAppSettingsKit override my TabBarItemTitle?

i am using InAppSettingsKit pod in my iOS app, developed without storyboard. I have a MainTabBarController where I initialize my ViewControllers. Everything works fine, BUT when I start the App in Simulator (where phone language is English) or on my physical device (where phone language is German) I have an issue in both cases. App starts, first VC is shown. When I tap on the last TabBarItem called "Einstellungen" it is automatically renamed to "Settings". Also my NavigationBar title is changed from "Einstellungen" to Settings. I tried several things, but I don't get what's the problem. Is there any constant I have to change inside InAppSettingsKit, so my VC is not renamed?

Thanks for any help!

import UIKit
import FirebaseAuth

class MainTabBarController: UITabBarController, UITabBarControllerDelegate {

//MARK: - View Life Cycle

override func viewDidLoad() {
    super.viewDidLoad()
    
    delegate = self
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    setupViews()
}

//MARK: - Functions

private func setupViews() {
    guard let user = Auth.auth().currentUser else { return }
    
    //First ViewController
    let firstVC = UINavigationController(rootViewController: VicinityViewController(currentUser: user))
    firstVC.navigationBar.tintColor = .mainBlue
    firstVC.navigationBar.prefersLargeTitles = true
    firstVC.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.mainBlue]
    firstVC.navigationBar.largeTitleTextAttributes = firstVC.navigationBar.titleTextAttributes
    let firstVCItem = UITabBarItem(title: "Beispiel1", image: UIImage(systemName: "circle.grid.hex"), selectedImage: UIImage(systemName: "circle.grid.hex.fill"))
    firstVC.tabBarItem = firstVCItem
    
    //Second ViewController
    let secondVC = ChatsViewController()
    let secondVCItem = UITabBarItem(title: "Beispiel2", image: UIImage(systemName: "camera"), selectedImage: UIImage(systemName: "camera.fill"))
    secondVC.tabBarItem = secondVCItem
    
    //Third ViewController
    let thirdVC = UINavigationController(rootViewController: SettingsViewController())
    thirdVC.navigationBar.prefersLargeTitles = true
    let thirdVCItem = UITabBarItem(title: "Einstellungen", image: UIImage(systemName: "gear"), selectedImage: UIImage(systemName: "gear.fill"))
    thirdVC.tabBarItem = thirdVCItem
    
    //Array of the controllers, displayed by the TabBarController
    let controllers = [firstVC, secondVC, thirdVC]
    self.viewControllers = controllers
}

//MARK: - Delegate

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
    print("Should select ViewController: \(viewController.title ?? "")?")
    return true;
   }
}

My SettingsViewController:

import UIKit
import InAppSettingsKit
import FirebaseAuth

enum SpecifierKeys: String {
case logout = "logout_preference"
}

class SettingsViewController: IASKAppSettingsViewController {

//MARK: - View Life Cycle

override func viewDidLoad() {
    super.viewDidLoad()
    
    setupViews()
    updateHiddenKeys()
    delegate = self

    NotificationCenter.default.addObserver(self, selector: #selector(settingDidChange(notification:)), name: Notification.Name.IASKSettingChanged, object: nil)
}
    
//MARK: - Functions

private func setupViews() {
    self.navigationItem.rightBarButtonItem = nil
}
        
@objc func settingDidChange(notification: Notification?) {
    updateHiddenKeys()
}

func updateHiddenKeys() {
    print(UserDefaults.standard.object(forKey: "name_preference") ?? "There is no value")
  }
}

extension SettingsViewController: IASKSettingsDelegate {
    
func settingsViewControllerDidEnd(_ settingsViewController: IASKAppSettingsViewController) {
    print("SettingsViewController did end")
}

func settingsViewController(_ settingsViewController: IASKAppSettingsViewController, buttonTappedFor specifier: IASKSpecifier) {
    guard let _ = specifier.key else { return }
    let Specifier: SpecifierKeys = specifier.key.map { SpecifierKeys(rawValue: $0) }!!
    switch Specifier {
    case .logout:
        print("Ausloggen gedrückt")
        Utilities.logout()
    }
  }
}

You don't seem to set the title of thirdVC . In this case (if the title is nil ), IASK sets it to NSLocalizedString(@"Settings", @"") .

So either set thirdVC.title or add "Settings" to your Localizable.strings file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM