How to dismiss PopViewController for another ViewController












1














I'm using ashleymills/Reachability to check if user is connected to the internet and if not I want to show a popup and if there was an internet connection I want the popup to disappear.
the first part was easy and I was able to do , but I couldn't dismiss the popup when there is internet connection



The main view:



 func checkConnection() {
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checkConnectivity = self
self.showPopUp(VC, parent: self)
}
func isConnect(){
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checknotConnectivity = self
VC.dismissVC()
}

@objc func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
isConnect()
case .cellular:
isConnect()
case .none:
checkConnection()
}
}


the popup view



var checkConnectivity : checkConnectivity?
func dismissVC() {
// self.dismiss(animated: false, completion: nil)
print("dismissVC")
}

protocol checkConnectivity {
func isConnect()
func checkConnection()
}


I could see the print in the debugger which means my code is being read , but does not dismiss.










share|improve this question
























  • What does this line mean but the second I could dismiss the popup when there is internet connection ? And about your Pop up, is it just a UIAlertController or your custom made Pop up using UIView ?
    – Shubham Bakshi
    Nov 12 at 6:45












  • it is wired, because you are saying it is printing "dismissVC" !! can you provide us more information ?
    – Mahgol Fa
    Nov 12 at 6:49










  • first sorry I was trying to see I can not dissmiss the popup when there is internet connection and no it,is not UIAlertController I will share my pop code for you to see it and for more info my isConnect() checkConnection() are protocols
    – Nouf
    Nov 12 at 7:13
















1














I'm using ashleymills/Reachability to check if user is connected to the internet and if not I want to show a popup and if there was an internet connection I want the popup to disappear.
the first part was easy and I was able to do , but I couldn't dismiss the popup when there is internet connection



The main view:



 func checkConnection() {
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checkConnectivity = self
self.showPopUp(VC, parent: self)
}
func isConnect(){
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checknotConnectivity = self
VC.dismissVC()
}

@objc func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
isConnect()
case .cellular:
isConnect()
case .none:
checkConnection()
}
}


the popup view



var checkConnectivity : checkConnectivity?
func dismissVC() {
// self.dismiss(animated: false, completion: nil)
print("dismissVC")
}

protocol checkConnectivity {
func isConnect()
func checkConnection()
}


I could see the print in the debugger which means my code is being read , but does not dismiss.










share|improve this question
























  • What does this line mean but the second I could dismiss the popup when there is internet connection ? And about your Pop up, is it just a UIAlertController or your custom made Pop up using UIView ?
    – Shubham Bakshi
    Nov 12 at 6:45












  • it is wired, because you are saying it is printing "dismissVC" !! can you provide us more information ?
    – Mahgol Fa
    Nov 12 at 6:49










  • first sorry I was trying to see I can not dissmiss the popup when there is internet connection and no it,is not UIAlertController I will share my pop code for you to see it and for more info my isConnect() checkConnection() are protocols
    – Nouf
    Nov 12 at 7:13














1












1








1







I'm using ashleymills/Reachability to check if user is connected to the internet and if not I want to show a popup and if there was an internet connection I want the popup to disappear.
the first part was easy and I was able to do , but I couldn't dismiss the popup when there is internet connection



The main view:



 func checkConnection() {
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checkConnectivity = self
self.showPopUp(VC, parent: self)
}
func isConnect(){
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checknotConnectivity = self
VC.dismissVC()
}

@objc func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
isConnect()
case .cellular:
isConnect()
case .none:
checkConnection()
}
}


the popup view



var checkConnectivity : checkConnectivity?
func dismissVC() {
// self.dismiss(animated: false, completion: nil)
print("dismissVC")
}

protocol checkConnectivity {
func isConnect()
func checkConnection()
}


I could see the print in the debugger which means my code is being read , but does not dismiss.










share|improve this question















I'm using ashleymills/Reachability to check if user is connected to the internet and if not I want to show a popup and if there was an internet connection I want the popup to disappear.
the first part was easy and I was able to do , but I couldn't dismiss the popup when there is internet connection



The main view:



 func checkConnection() {
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checkConnectivity = self
self.showPopUp(VC, parent: self)
}
func isConnect(){
let VC = self.getStoryBoard().instantiateViewController(withIdentifier: "checkConnection") as! checkConnection
VC.checknotConnectivity = self
VC.dismissVC()
}

@objc func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
isConnect()
case .cellular:
isConnect()
case .none:
checkConnection()
}
}


the popup view



var checkConnectivity : checkConnectivity?
func dismissVC() {
// self.dismiss(animated: false, completion: nil)
print("dismissVC")
}

protocol checkConnectivity {
func isConnect()
func checkConnection()
}


I could see the print in the debugger which means my code is being read , but does not dismiss.







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 9:10

























asked Nov 12 at 6:41









Nouf

15313




15313












  • What does this line mean but the second I could dismiss the popup when there is internet connection ? And about your Pop up, is it just a UIAlertController or your custom made Pop up using UIView ?
    – Shubham Bakshi
    Nov 12 at 6:45












  • it is wired, because you are saying it is printing "dismissVC" !! can you provide us more information ?
    – Mahgol Fa
    Nov 12 at 6:49










  • first sorry I was trying to see I can not dissmiss the popup when there is internet connection and no it,is not UIAlertController I will share my pop code for you to see it and for more info my isConnect() checkConnection() are protocols
    – Nouf
    Nov 12 at 7:13


















  • What does this line mean but the second I could dismiss the popup when there is internet connection ? And about your Pop up, is it just a UIAlertController or your custom made Pop up using UIView ?
    – Shubham Bakshi
    Nov 12 at 6:45












  • it is wired, because you are saying it is printing "dismissVC" !! can you provide us more information ?
    – Mahgol Fa
    Nov 12 at 6:49










  • first sorry I was trying to see I can not dissmiss the popup when there is internet connection and no it,is not UIAlertController I will share my pop code for you to see it and for more info my isConnect() checkConnection() are protocols
    – Nouf
    Nov 12 at 7:13
















What does this line mean but the second I could dismiss the popup when there is internet connection ? And about your Pop up, is it just a UIAlertController or your custom made Pop up using UIView ?
– Shubham Bakshi
Nov 12 at 6:45






What does this line mean but the second I could dismiss the popup when there is internet connection ? And about your Pop up, is it just a UIAlertController or your custom made Pop up using UIView ?
– Shubham Bakshi
Nov 12 at 6:45














it is wired, because you are saying it is printing "dismissVC" !! can you provide us more information ?
– Mahgol Fa
Nov 12 at 6:49




it is wired, because you are saying it is printing "dismissVC" !! can you provide us more information ?
– Mahgol Fa
Nov 12 at 6:49












first sorry I was trying to see I can not dissmiss the popup when there is internet connection and no it,is not UIAlertController I will share my pop code for you to see it and for more info my isConnect() checkConnection() are protocols
– Nouf
Nov 12 at 7:13




first sorry I was trying to see I can not dissmiss the popup when there is internet connection and no it,is not UIAlertController I will share my pop code for you to see it and for more info my isConnect() checkConnection() are protocols
– Nouf
Nov 12 at 7:13












1 Answer
1






active

oldest

votes


















1














It is because you're initialising a controller in checkConnection method and popping up but in isConnect method you're again initialising the controller which is making a different instance of same controller and hence the previously initialised controller is not getting dismissed.



Try making the controller in checkConnection method as global and dismiss that controller in isConnect method






share|improve this answer





















  • Thank you it working now
    – Nouf
    Nov 12 at 9:18










  • Great! Please mark it as an accepted answer:)
    – Shankey
    Nov 12 at 9:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257047%2fhow-to-dismiss-popviewcontroller-for-another-viewcontroller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It is because you're initialising a controller in checkConnection method and popping up but in isConnect method you're again initialising the controller which is making a different instance of same controller and hence the previously initialised controller is not getting dismissed.



Try making the controller in checkConnection method as global and dismiss that controller in isConnect method






share|improve this answer





















  • Thank you it working now
    – Nouf
    Nov 12 at 9:18










  • Great! Please mark it as an accepted answer:)
    – Shankey
    Nov 12 at 9:19
















1














It is because you're initialising a controller in checkConnection method and popping up but in isConnect method you're again initialising the controller which is making a different instance of same controller and hence the previously initialised controller is not getting dismissed.



Try making the controller in checkConnection method as global and dismiss that controller in isConnect method






share|improve this answer





















  • Thank you it working now
    – Nouf
    Nov 12 at 9:18










  • Great! Please mark it as an accepted answer:)
    – Shankey
    Nov 12 at 9:19














1












1








1






It is because you're initialising a controller in checkConnection method and popping up but in isConnect method you're again initialising the controller which is making a different instance of same controller and hence the previously initialised controller is not getting dismissed.



Try making the controller in checkConnection method as global and dismiss that controller in isConnect method






share|improve this answer












It is because you're initialising a controller in checkConnection method and popping up but in isConnect method you're again initialising the controller which is making a different instance of same controller and hence the previously initialised controller is not getting dismissed.



Try making the controller in checkConnection method as global and dismiss that controller in isConnect method







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 8:27









Shankey

613




613












  • Thank you it working now
    – Nouf
    Nov 12 at 9:18










  • Great! Please mark it as an accepted answer:)
    – Shankey
    Nov 12 at 9:19


















  • Thank you it working now
    – Nouf
    Nov 12 at 9:18










  • Great! Please mark it as an accepted answer:)
    – Shankey
    Nov 12 at 9:19
















Thank you it working now
– Nouf
Nov 12 at 9:18




Thank you it working now
– Nouf
Nov 12 at 9:18












Great! Please mark it as an accepted answer:)
– Shankey
Nov 12 at 9:19




Great! Please mark it as an accepted answer:)
– Shankey
Nov 12 at 9:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257047%2fhow-to-dismiss-popviewcontroller-for-another-viewcontroller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues