last day (15 days later) » 

11:58 AM
0
A: Swift - push & pop UIViewcontroller not working

Mohit ManglaCheck navigationController instance in below line of code: self.navigationController?.pushViewController(imageCollectionView, animated: true) If self.navigationController is nil then you may have not embedded navigation controller with your ExampleViewController. Then you need to embed your f...

 
it is nil :( But I don't really get how I can embed my vc with a navigation controller.
 
Go to story board. Select your controller in storyboard. Then go to editor and embed i navigation controller. Attaching screenshot in answer.
 
should I do this for both of them?
 
Only for the first view controller.
 
nope that it is still not working
do I have to change anything else? Or somehow link it with the second ViewController?
 
11:58 AM
No, when you call <pre> self.navigationController?.pushViewController(B, animated: true) <code> in A viewcontroller then same navigation can be used for B as well because navigation manages a view controller stack and when we push a nnew view controller, navigation pushes the new VC into that stack.
 
ok that makes sense but why is it still not working?
and btw navigationController is still
@IBAction func editButtonTapped(_ sender: Any) {
    let imageCollectionView = self.storyboard?.instantiateViewController(withIdentifier: "ImageCollectionVC") as! ImageCollectionViewController
    imageCollectionView.delegate = self
    if (self.navigationController == nil){
        print("fuck")
    }
    self.navigationController?.pushViewController(imageCollectionView, animated: true)
    print("editButtonTapped")
}
 
have you embeded it? can you share screenshot of your storyboard?
 
yes one sec
how can I send a screenshot here?
oh I need 100 reps for that..
ok wait
 
wait
No
That is not your first View conntroller / initialViewController
 
no
 
12:04 PM
have you uploaded your sourcecode somewhere?
 
yes
look at my question
its on github
 
but its very messy :D
 
It's ok
checking your code
 
its just about HomeViewController and ImageViewController
 
12:11 PM
give me anny valid email address
 
it doesn`t have to be a your email
just try asdflökajsdf@gmail.com or sth
some things are german so I hope you get it :D
 
Nope
not able to go to homeviewcontroller/ exampleviewcontroller
 
just fill in all the fields
with random name
oh wait
its not working
wtf
ok got it
try mohit@mail.com
password mohit12
 
oh sorry
I got it worked
le me check the issue
 
sure
 
12:23 PM
fixed your issue
func transitionToHome () {

let homeViewCotnroller =
storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.homeViewController) as? ExampleViewController
let navigationController = UINavigationController(rootViewController: homeViewCotnroller!)

view.window?.rootViewController = navigationController
view.window?.makeKeyAndVisible()
}
you have method transitionToHome at 2 places
replace it with it
it will work
 
but thats in login and signUp View right?
 
this is the result?
1. In SignUpViewController
2. In LoginViewController
 
yes it is
ok wait let me check that
 
ok but do I need the second NavigationController now as well?
 
12:28 PM
remove the NavigationController from storyboard which you embeded. We are doing same programatically now.
workinng for you?
 
trying it now
um well yes it does
but how can I hide the navigation bar?
 
navigationController?.setNavigationBarHidden(true, animated: animated)
in view will appear
 
where is view will appear :D
 
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
It is a view lifecycle method
 
in HomeViewController?
 
12:33 PM
where ever you want to hide
 
oh makes sense
 
whichever view you want without navigation bar... just place this view lifecycle method
 
ok there is one more proble
m
 
tell me faster
I nneed to leave for a meetinng
 
if you click the close button in ImageCollectionViewController and try it again it doesn't work anymore
 
12:37 PM
working for me
just upload all channges to git hub
 
oh wait i fixed that i know what the problem was
thanks man!
wait
on emore thing :D
how can i change the animation
 
which animation
?
 
i want it to go transition vertical
not horizontal
 
when you push... it works horizontaly
 
from HomeViewController to ImageCollectionViewController
 
12:38 PM
when you present... it works vertically
 
ok so I change that
and backwards?
dismiss?
 
backwards?
vertically - dismiss
horizontaly - pop
 
from ImageCollection to HomeVC
alright
perfect, thanks
really appreciate your help ma
n
 
Anytime man
happy coding
 
u2
cheers
 
12:40 PM
bye
 
waaaait :D i cant just replace pop with dismiss
   navigationController?.dismissViewController(animated: true)
thats not working
 
if you present then only you can dismiss
if you push then only you can pop
self.present(vc, animated: true, completion: nil)

dismiss(animated: true, completion: nil)
 
alright :D Now I dont have anyore questions
 
really need to attend a meeting... Mail your problem at mohitmangla2091@gmail.com
 
thanks again
 
12:44 PM
you can like my question if you are happy with the help... :D
welcome
 

last day (15 days later) »