0

Code used to work with Swift 1 but now does not and here is my issue. (did check other questions but this is slightly different, and enough so that the other solututions did not work.

So I am trying to present a logon screen which I do as follows enter image description here

and it works fine, the user enters in their username and password. I then programmatically check they can log in and all still good and do the unwind as follows:

self.performSegueWithIdentifier("unwindGoToTeamPage", sender: self)

But the following code does not fire even though the func is called. I know that because I had a print statement in their for debuging and it shows on the console:

@IBAction func unwindGoToTeamPage(sender: UIStoryboardSegue){
    print("In here")
    self.performSegueWithIdentifier("goToTeamPage", sender: self)
    }

Now I know its related to the same reason that at the start of the ViewController life cycle you can not call a

self.performSegueWithIdentifier("goToTeamPage", sender: self)

as it wont work in the

override func viewDidLoad() {
        super.viewDidLoad()
    }

or the

 override func viewWillAppear(animated: Bool) {
    }

but only in the

override func viewDidAppear(animated: Bool) {
        if appDelegate.tkData[0] == "1"
        {
            self.performSegueWithIdentifier("goToTeamPage", sender: self)
        }
    }

In Swift 1 and Objective-C I used to put in a timer and all was good but that no longer works and I prefer to put in a solid solution that is not a hack. I think the solution involves waiting till the logon viewcontroller is completely dismissed but not sure the correct way to achieve it.

Could a dispatch to the main queue be an option. I will try that while I wait if someone has an answer and post an update. I also noted it works just fine on a iPhone or iPod but its the iPad where the issue is unsolved.

Appreciate any pointers to solve this problem. Thanks

Update, Yes I did try the UITextField solutions but that appears not to be the issue in this instance. I am slowly identifying the issue as one view controller not yet finished before the

 self.performSegueWithIdentifier("goToTeamPage", sender: self)

fires.

I also apologies that i failed to mention the console message which is: Warning: Attempt to present <new view controller> on <current view controller> whose view is not in the window hierarchy!

So I see my issue is as needing to sort of run the logon viewcontroller in such a way as to have the orignial viewcontroller get a message that the logon view conntroller has finished and only then fire the

 self.performSegueWithIdentifier("goToTeamPage", sender: self)

SO is there are way to get a call back of some sort to tell the original view controller that the child view controller has completely finished so I can then call the next function only once the child view controller is finished.

Thanks for any help on this.

Community
  • 1
  • 1
timv
  • 3,346
  • 4
  • 34
  • 43
  • Can you please check if [this thread](http://stackoverflow.com/questions/32643765/ios-9-segue-causes-app-to-freeze-no-crash-or-error-thrown/32661264#32661264) solves your issue. – Abhinav Oct 06 '15 at 04:12
  • Thanks Abhinav, no as I dont have the UITextField issue. I did look at those issues and try the solutions but it did not help. – timv Oct 06 '15 at 22:14
  • Updated my question with more info incase it helps – timv Oct 06 '15 at 22:50
  • Are you presenting login VC on top of your VC from where you want to perform segue? If so then why don't you utilize completion block? If you could share GitHub link to your project, I can take a look. – Abhinav Oct 07 '15 at 00:26
  • have not registered with github yet but your solution is spot on as i need to simply implement a completion block. I am trying to find example code to use as unsure how to implement it, but trying to figure it out now. if you have an example link that would be appreciated else I will keep digging at the issue. thanks again – timv Oct 07 '15 at 00:30
  • I am actually away from my system and would reach it in couple of hours. Would surely share some code examples. If by then u did not find any luck. This is such a hot topic that I'm sure u will find one before me :-), good luck! – Abhinav Oct 07 '15 at 00:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91539/discussion-between-tjv-and-abhinav). – timv Oct 07 '15 at 02:54

1 Answers1

0

I have this sort of working but feel its really just another hack and though will get me out of trouble this time disappointed I could not find the correct way of doing it.

So the issue is mainly with the modally presentation of the logon screen where once it is dismissed it takes however many microseconds to be removed from the view hierarchy. Trying to move to another viewcontroller with

self.performSegueWithIdentifier("goToTeamPage", sender: self)

will not work which is my dilemma.

So to get around it I made the logon screen a full screen (not popover or modally) and then put the code

self.performSegueWithIdentifier("goToTeamPage", sender: self)

in the

override func viewDidAppear(animated: Bool) {  
     self.performSegueWithIdentifier("goToTeamPage", sender: self)        
}

function.

Not the best solution as the logon screen is now full screen and while ok on the iphone not the best on the iPad.

So, sort of fixed but as a hack and work around and STILL KEEN if anyone has a solution where I can go back to the modally view for the logon screen.

timv
  • 3,346
  • 4
  • 34
  • 43