How to dismiss PopViewController for another ViewController
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
add a comment |
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
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 aUIAlertController
or your custom made Pop up usingUIView
?
– 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
add a comment |
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
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
ios swift
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 aUIAlertController
or your custom made Pop up usingUIView
?
– 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
add a comment |
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 aUIAlertController
or your custom made Pop up usingUIView
?
– 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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 usingUIView
?– 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