How to segue to previous screen using Swift without losing data in swift 4
I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:
self.performSegue(withIdentifier: "sugueToRules", sender: self)
on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)
when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.
how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?
i'm using swift 4
swift segue
add a comment |
I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:
self.performSegue(withIdentifier: "sugueToRules", sender: self)
on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)
when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.
how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?
i'm using swift 4
swift segue
Make sure that they are managed by aUINavigationController
. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have todismiss
(or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.
– Alladinian
Nov 22 '18 at 11:22
@Alladinian great answer, put it as an answer and i'll accept it
– Chief Madog
Nov 22 '18 at 11:28
@ChiefMadog Done. Glad that helped you :)
– Alladinian
Nov 22 '18 at 11:30
add a comment |
I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:
self.performSegue(withIdentifier: "sugueToRules", sender: self)
on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)
when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.
how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?
i'm using swift 4
swift segue
I have a button from my create account page that opens up another view controller that has some information in it.
i move it by doing a segue:
self.performSegue(withIdentifier: "sugueToRules", sender: self)
on my other Viewcontroller i have a back button that connects form the storyboard, to the create account one (the precious one)
when i go back i lose all my data that i put on the create account,
so i must open a new instance of it.
how do i keep all my data of it when i go back ?
do i have to save a local file somewhere and load it when i come back ?
i'm using swift 4
swift segue
swift segue
edited Nov 22 '18 at 11:19
Chief Madog
asked Nov 22 '18 at 11:13
Chief MadogChief Madog
5691926
5691926
Make sure that they are managed by aUINavigationController
. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have todismiss
(or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.
– Alladinian
Nov 22 '18 at 11:22
@Alladinian great answer, put it as an answer and i'll accept it
– Chief Madog
Nov 22 '18 at 11:28
@ChiefMadog Done. Glad that helped you :)
– Alladinian
Nov 22 '18 at 11:30
add a comment |
Make sure that they are managed by aUINavigationController
. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have todismiss
(or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.
– Alladinian
Nov 22 '18 at 11:22
@Alladinian great answer, put it as an answer and i'll accept it
– Chief Madog
Nov 22 '18 at 11:28
@ChiefMadog Done. Glad that helped you :)
– Alladinian
Nov 22 '18 at 11:30
Make sure that they are managed by a
UINavigationController
. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss
(or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.– Alladinian
Nov 22 '18 at 11:22
Make sure that they are managed by a
UINavigationController
. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have to dismiss
(or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.– Alladinian
Nov 22 '18 at 11:22
@Alladinian great answer, put it as an answer and i'll accept it
– Chief Madog
Nov 22 '18 at 11:28
@Alladinian great answer, put it as an answer and i'll accept it
– Chief Madog
Nov 22 '18 at 11:28
@ChiefMadog Done. Glad that helped you :)
– Alladinian
Nov 22 '18 at 11:30
@ChiefMadog Done. Glad that helped you :)
– Alladinian
Nov 22 '18 at 11:30
add a comment |
3 Answers
3
active
oldest
votes
Make sure that they are managed by a UINavigationController
. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.
The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.
add a comment |
Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
add a comment |
you need to use UINavigationController for navigating UIViewController like -
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%2f53429726%2fhow-to-segue-to-previous-screen-using-swift-without-losing-data-in-swift-4%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Make sure that they are managed by a UINavigationController
. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.
The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.
add a comment |
Make sure that they are managed by a UINavigationController
. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.
The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.
add a comment |
Make sure that they are managed by a UINavigationController
. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.
The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.
Make sure that they are managed by a UINavigationController
. Then the back button will do its job just fine (no need for you to 'wire' something -- this is the default behaviour). Right now it appears that you are allocating a new controller each time you go back.
The same applies to a modally presented controller (with a custom close button for example), although you have to dismiss (or use an exit segue) instead of firing up a segue pointing back.
answered Nov 22 '18 at 11:30
AlladinianAlladinian
28.2k47073
28.2k47073
add a comment |
add a comment |
Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
add a comment |
Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
add a comment |
Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
Passing segue to previous screen will creates a new instance of the previous viewcontroller. It it better to be bound in navigation controller and popout the presented screen using when back navigation is not required.
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true, completion: nil)
answered Nov 22 '18 at 11:40
Vaisakh KPVaisakh KP
172217
172217
add a comment |
add a comment |
you need to use UINavigationController for navigating UIViewController like -
add a comment |
you need to use UINavigationController for navigating UIViewController like -
add a comment |
you need to use UINavigationController for navigating UIViewController like -
you need to use UINavigationController for navigating UIViewController like -
answered Nov 22 '18 at 11:52
Deepti RaghavDeepti Raghav
288217
288217
add a comment |
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.
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%2f53429726%2fhow-to-segue-to-previous-screen-using-swift-without-losing-data-in-swift-4%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
Make sure that they are managed by a
UINavigationController
. Then the back button will do its job just fine. Right now it appears that you are allocating a new controller each time you go back. The same applies to a modally presented controller, although you have todismiss
(or use an exit segue) instead of firing up a segue pointing back. I hope that this makes sense.– Alladinian
Nov 22 '18 at 11:22
@Alladinian great answer, put it as an answer and i'll accept it
– Chief Madog
Nov 22 '18 at 11:28
@ChiefMadog Done. Glad that helped you :)
– Alladinian
Nov 22 '18 at 11:30