K
K
Konstantin2019-06-16 19:08:25
iOS
Konstantin, 2019-06-16 19:08:25

How to activate the transition to Swift?

People, tell me please.
I need to make a check during the opening of the view and perform the transition.
Now I'm doing it like this

if (login != "" && pass != ""){
                //Проводим авторизацию
                if auth(login: "", pass: "")==true {
                    print("Auth true")
                    if let personalCabinet = self.storyboard?.instantiateViewController(withIdentifier: "ShowPersonalCabinetDetailAction") as? PersonalCabinetInfoView { 
                        personalCabinet.modalTransitionStyle = .crossDissolve 
                        personalCabinet.modalPresentationStyle = .overCurrentContext
                        self.present(personalCabinet, animated: true, completion: nil)
                    }
                }else{
                    print("Авторизация не удалась")
                }
            }else{
                print("Авторизационные даты не заполнены")
            }

It enters the block with performSegue normally, but performSegue itself ignores it.
I execute the code in override func viewDidLoad()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NSA-bot, 2019-06-16
@SatanaKonst

You can do it without Segway, for example, like this:
I don’t know what the class attached to the target view controller is called, but I assumed that the name is ShowPersonalCabinetDetailAction. If anything, put it like you have.

if (login != "" && pass != ""){
    //Проводим авторизацию
    if auth(login: "", pass: "")==true {
      print("Auth true")
      
      // Вывод контроллера
      if let personalCabinet = self.storyboard?.instantiateViewController(withIdentifier: "ShowPersonalCabinetDetailAction") as? ShowPersonalCabinetDetailAction { // после as? это название класса вашего контроллера, куда переходите, точно не знаю какое, предположил, что такое же как и идентификатор
        personalCabinet.modalTransitionStyle = .crossDissolve //  тут можно поменять на другие типы анимации появления контроллера
        personalCabinet.modalPresentationStyle = .overCurrentContext
        self.present(personalCabinet, animated: true, completion: nil)
      }
      
    }else{
      print("Авторизация не удалась")
    }
  }else{
    print("Авторизационные даты не заполнены")
  }

I
iMaximus, 2019-06-17
@iMaximus

This won't work in viewDidLoad because the view is not actually attached to the window yet. You can try moving it to viewDidAppear. But the code, of course, is not ice, 2 if else instead of guard, not to mention what is written in separate functions, but here they are only called. And there is another scary word patterns :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question