0

i am very new to all the swift stuff and i hope somebody can help me with this problem

I have set up the following

enter image description here

  • Tabbar Controler with 1 Navigationcontroller

So if i start the application everything is fine and the view controller with the "Button" is loaded in tab 1

Now i want to navigate within tab1 to another view controller with a "label"

Thats what i did :

Connected the button to the new view controller with the label as "Show seque"

If i start the application and click on the button then the new view controller with the label slides and and shows the back button

-- > So everything is OK here in my eyes ..it slides only "once"

But if i add a UIBarButtonItem in the View Controller on the top left programatically and want to navigate programatically to the view controller with the label it is loading twice. I am using the following code:

@objc func settingsTapped() {
    
    
let new = storyboard?.instantiateViewController(withIdentifier: "new") as! NewViewController

self.navigationController?.pushViewController(new, animated:  true)

    
}

The problem here is that the view controller is loaded always twice. It slides and slides again so i have to click two times to go back to the main view controller

Can anybody help me here please ?

I do not understand why this happens because if i click on the button with the "Show seque only" then it slides only once as expected.

jps
  • 20,041
  • 15
  • 75
  • 79
Frank
  • 2,738
  • 2
  • 14
  • 19
  • How many times is settingsTapped called? – Don Dec 22 '20 at 00:10
  • Hi Don ..only once ! I have also made a complete new test project and have exactly the same problem . First i thought i have made a mistake in my other project but this is not the case – Frank Dec 22 '20 at 00:13
  • I'm assuming you didn't also connect the UIBarButtonItem to the new view controller with a segue? – Don Dec 22 '20 at 00:19
  • No i did not do this.. How can i make a seque programatically to the view controller with the label ? – Frank Dec 22 '20 at 00:34
  • This might help: https://stackoverflow.com/a/54201390/10116367 – Kevvv Dec 22 '20 at 00:43
  • Hi thanx for the info but it does not help. I tried with self.view.isUserInteractionEnabled = true in viewdidappear. and false on the settingsTapped but it still slides twice – Frank Dec 22 '20 at 00:54

1 Answers1

0

Ok i have fixed the problem. Many thanx also for the answers here !!

This was really a hard "nut" and i have searched a long time how to fix this

It was sliding twice because while creating the UiBarButtomItem i used this

 leftbutton.addTarget(self, action: #selector(settingsTapped), for: .allEvents)

I have replaced ".allEvents" with ".touchUpInside" and now it is working as expected and slides only once

 leftbutton.addTarget(self, action: #selector(settingsTapped), for: .touchUpInside)

This works fine now.

I really do not know why .allEvents is producing a twice sliding

Frank
  • 2,738
  • 2
  • 14
  • 19