[ad_1]
I’m working with one challenge on Xcode with SnapKit and with out storyboard.
I did not contact AppDelegate
I’ve this code on SceneDelegate
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.makeKeyAndVisible()
window?.rootViewController = TabBarController()
}
}
Venture’s hierarchy like that:
- TabBarController
- ViewController
- HomeCollectionViewCell
-
ShopPage(Group)
… -
MessagePage(Group)
… -
ProfilePage(Group)
- ProfileViewController
- SettingsViewController
I need to open SettingsViewController when settingsButton(on ProfileViewController) tupped
That is my code within the TabBarController:
import UIKit
class TabBarController: UITabBarController {
override func viewDidLoad() {
tremendous.viewDidLoad()
self.setupTabs()
selectedIndex = 3
tabBar.backgroundColor = .systemBackground
tabBar.tintColor = UIColor(purple: 0, inexperienced: 155/255, blue: 247/255, alpha: 1)
}
//MARK: - Tab Setup
non-public func setupTabs(){
let residence = self.createNav(title: "Dwelling", picture: UIImage(systemName: "home"), vc: ViewController())
let store = self.createNav(title: "Store", picture: UIImage(systemName: "bag"), vc: ShopViewController())
let message = self.createNav(title: "Message", picture: UIImage(systemName: "ellipsis.message"), vc: MessageViewController())
let profile = self.createNav(title: "Profile", picture: UIImage(systemName: "individual"), vc: ProfileViewController())
self.setViewControllers([home, shop, message, profile], animated: true)
}
non-public func createNav(title: String, picture: UIImage?, vc: UIViewController) -> UINavigationController{
let nav = UINavigationController(rootViewController: vc)
nav.tabBarItem.title = title
nav.tabBarItem.picture = picture
return nav
}
}
That is my code within the ProfileViewController:
class ProfileViewController: UIViewController {
non-public lazy var settingButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "gearshape"), for: .regular)
button.addTarget(self, motion: #selector(openSettings), for: .touchUpInside)
return button
}()
override func viewDidLoad() {
tremendous.viewDidLoad()
view.backgroundColor = UIColor(purple: 250/255, inexperienced: 250/255, blue: 250/255, alpha: 1)
setupUI()
}
@objc non-public func openSettings() {
let settingsViewController = SettingsViewController()
navigationController?.pushViewController(settingsViewController, animated: true)
}
}
non-public extension ProfileViewController {
func setupUI() {
setupViews()
setupConstraints()
}
func setupViews() {
view.addSubview(settingButton)
}
func setupConstraints() {
settingButton.snp.makeConstraints { make in
make.heart.equalToSuperview()
}
}
}
However after I tupped settingButton nothing taking place
I attempted to set rootViewController like that on Scene Delegate:
window?.rootViewController = UINavigationController(rootViewController: TabBarController())
Additionally I attempted right here set ProfileViewController as a rootViewController
Additionally I attempted with current methodology:
@objc non-public func openSettings() {
let settingsViewController = SettingsViewController()
current(settingsViewController, animated: true)
}
did’t helped(
[ad_2]