Master/Detail view: from Add view to Detail view and vice versa
This might be a very simple question, but I could not find a clear answer on how to achieve this properly (= elegantly).
I have a simple list (table view) of items (called models in the screenshot below). When I add a new item, I have a modal segue to display the Add view
.
When hitting Save
, this currently goes back to the table view.
In the list (table view), when hitting on an item, it shows the detail view
.
Whished behaviour
- When hitting
save
when adding a new item, thedetail view
should be shown, instead of going back to the list - When hitting
edit
in thedetail view
, it should show theadd (edit actually) view
for the user to modify the model
This is the same behaviour as the native iOS Contacts
app.
Thanks in advance for the help, and sorry for the simplicity of the question!
Here is what I tried
Using a Custom Segue on a duplicated segue for showing the details
class FadeSegue: UIStoryboardSegue {
override func perform() {
guard let destinationView = self.destination.view else {
// Fallback to no fading
self.source.present(self.destination, animated: false, completion: nil)
return
}
destinationView.alpha = 0
self.source.view?.addSubview(destinationView)
UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
destinationView.alpha = 1
}, completion: { _ in
destinationView.removeFromSuperview()
self.source.present(self.destination, animated: false, completion: nil)
})
}
}
and on Save
for the new model (in AddModelViewController), I call this in the list (table) ViewController:
self.dismiss(animated: false, completion: {
self.performSegue(withIdentifier: "detailViewSegueAfterNewModel", sender: nil)
})
ios swift
|
show 3 more comments
This might be a very simple question, but I could not find a clear answer on how to achieve this properly (= elegantly).
I have a simple list (table view) of items (called models in the screenshot below). When I add a new item, I have a modal segue to display the Add view
.
When hitting Save
, this currently goes back to the table view.
In the list (table view), when hitting on an item, it shows the detail view
.
Whished behaviour
- When hitting
save
when adding a new item, thedetail view
should be shown, instead of going back to the list - When hitting
edit
in thedetail view
, it should show theadd (edit actually) view
for the user to modify the model
This is the same behaviour as the native iOS Contacts
app.
Thanks in advance for the help, and sorry for the simplicity of the question!
Here is what I tried
Using a Custom Segue on a duplicated segue for showing the details
class FadeSegue: UIStoryboardSegue {
override func perform() {
guard let destinationView = self.destination.view else {
// Fallback to no fading
self.source.present(self.destination, animated: false, completion: nil)
return
}
destinationView.alpha = 0
self.source.view?.addSubview(destinationView)
UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
destinationView.alpha = 1
}, completion: { _ in
destinationView.removeFromSuperview()
self.source.present(self.destination, animated: false, completion: nil)
})
}
}
and on Save
for the new model (in AddModelViewController), I call this in the list (table) ViewController:
self.dismiss(animated: false, completion: {
self.performSegue(withIdentifier: "detailViewSegueAfterNewModel", sender: nil)
})
ios swift
Why not segue to the details when the Save button is pressed? What have you tried?
– FJ de Brienne
Dec 31 '18 at 13:35
Because it does not animate as it does in the Contacts app when you add a new contact
– vomi
Dec 31 '18 at 16:19
In the contacts app, the Add Contact screen is presented modally. When a contact is added, the Contact Details screen for the newly added Contact are pushed in the UINavigationController stack. You can do the same thing using a completionBlock on the dismissal of the modally presented View Controller, no?
– FJ de Brienne
Dec 31 '18 at 20:06
That's the idea, but doing so does not exactly result in what's whished. Even though the animated flag is false, you can shortly see the dismissal before the Details View is pushed :/
– vomi
Jan 2 at 17:57
have you tried doing the dismissal in a completion block of the presentation?
– FJ de Brienne
Jan 2 at 17:58
|
show 3 more comments
This might be a very simple question, but I could not find a clear answer on how to achieve this properly (= elegantly).
I have a simple list (table view) of items (called models in the screenshot below). When I add a new item, I have a modal segue to display the Add view
.
When hitting Save
, this currently goes back to the table view.
In the list (table view), when hitting on an item, it shows the detail view
.
Whished behaviour
- When hitting
save
when adding a new item, thedetail view
should be shown, instead of going back to the list - When hitting
edit
in thedetail view
, it should show theadd (edit actually) view
for the user to modify the model
This is the same behaviour as the native iOS Contacts
app.
Thanks in advance for the help, and sorry for the simplicity of the question!
Here is what I tried
Using a Custom Segue on a duplicated segue for showing the details
class FadeSegue: UIStoryboardSegue {
override func perform() {
guard let destinationView = self.destination.view else {
// Fallback to no fading
self.source.present(self.destination, animated: false, completion: nil)
return
}
destinationView.alpha = 0
self.source.view?.addSubview(destinationView)
UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
destinationView.alpha = 1
}, completion: { _ in
destinationView.removeFromSuperview()
self.source.present(self.destination, animated: false, completion: nil)
})
}
}
and on Save
for the new model (in AddModelViewController), I call this in the list (table) ViewController:
self.dismiss(animated: false, completion: {
self.performSegue(withIdentifier: "detailViewSegueAfterNewModel", sender: nil)
})
ios swift
This might be a very simple question, but I could not find a clear answer on how to achieve this properly (= elegantly).
I have a simple list (table view) of items (called models in the screenshot below). When I add a new item, I have a modal segue to display the Add view
.
When hitting Save
, this currently goes back to the table view.
In the list (table view), when hitting on an item, it shows the detail view
.
Whished behaviour
- When hitting
save
when adding a new item, thedetail view
should be shown, instead of going back to the list - When hitting
edit
in thedetail view
, it should show theadd (edit actually) view
for the user to modify the model
This is the same behaviour as the native iOS Contacts
app.
Thanks in advance for the help, and sorry for the simplicity of the question!
Here is what I tried
Using a Custom Segue on a duplicated segue for showing the details
class FadeSegue: UIStoryboardSegue {
override func perform() {
guard let destinationView = self.destination.view else {
// Fallback to no fading
self.source.present(self.destination, animated: false, completion: nil)
return
}
destinationView.alpha = 0
self.source.view?.addSubview(destinationView)
UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
destinationView.alpha = 1
}, completion: { _ in
destinationView.removeFromSuperview()
self.source.present(self.destination, animated: false, completion: nil)
})
}
}
and on Save
for the new model (in AddModelViewController), I call this in the list (table) ViewController:
self.dismiss(animated: false, completion: {
self.performSegue(withIdentifier: "detailViewSegueAfterNewModel", sender: nil)
})
ios swift
ios swift
edited Jan 2 at 18:05
vomi
asked Dec 31 '18 at 9:28
vomivomi
12110
12110
Why not segue to the details when the Save button is pressed? What have you tried?
– FJ de Brienne
Dec 31 '18 at 13:35
Because it does not animate as it does in the Contacts app when you add a new contact
– vomi
Dec 31 '18 at 16:19
In the contacts app, the Add Contact screen is presented modally. When a contact is added, the Contact Details screen for the newly added Contact are pushed in the UINavigationController stack. You can do the same thing using a completionBlock on the dismissal of the modally presented View Controller, no?
– FJ de Brienne
Dec 31 '18 at 20:06
That's the idea, but doing so does not exactly result in what's whished. Even though the animated flag is false, you can shortly see the dismissal before the Details View is pushed :/
– vomi
Jan 2 at 17:57
have you tried doing the dismissal in a completion block of the presentation?
– FJ de Brienne
Jan 2 at 17:58
|
show 3 more comments
Why not segue to the details when the Save button is pressed? What have you tried?
– FJ de Brienne
Dec 31 '18 at 13:35
Because it does not animate as it does in the Contacts app when you add a new contact
– vomi
Dec 31 '18 at 16:19
In the contacts app, the Add Contact screen is presented modally. When a contact is added, the Contact Details screen for the newly added Contact are pushed in the UINavigationController stack. You can do the same thing using a completionBlock on the dismissal of the modally presented View Controller, no?
– FJ de Brienne
Dec 31 '18 at 20:06
That's the idea, but doing so does not exactly result in what's whished. Even though the animated flag is false, you can shortly see the dismissal before the Details View is pushed :/
– vomi
Jan 2 at 17:57
have you tried doing the dismissal in a completion block of the presentation?
– FJ de Brienne
Jan 2 at 17:58
Why not segue to the details when the Save button is pressed? What have you tried?
– FJ de Brienne
Dec 31 '18 at 13:35
Why not segue to the details when the Save button is pressed? What have you tried?
– FJ de Brienne
Dec 31 '18 at 13:35
Because it does not animate as it does in the Contacts app when you add a new contact
– vomi
Dec 31 '18 at 16:19
Because it does not animate as it does in the Contacts app when you add a new contact
– vomi
Dec 31 '18 at 16:19
In the contacts app, the Add Contact screen is presented modally. When a contact is added, the Contact Details screen for the newly added Contact are pushed in the UINavigationController stack. You can do the same thing using a completionBlock on the dismissal of the modally presented View Controller, no?
– FJ de Brienne
Dec 31 '18 at 20:06
In the contacts app, the Add Contact screen is presented modally. When a contact is added, the Contact Details screen for the newly added Contact are pushed in the UINavigationController stack. You can do the same thing using a completionBlock on the dismissal of the modally presented View Controller, no?
– FJ de Brienne
Dec 31 '18 at 20:06
That's the idea, but doing so does not exactly result in what's whished. Even though the animated flag is false, you can shortly see the dismissal before the Details View is pushed :/
– vomi
Jan 2 at 17:57
That's the idea, but doing so does not exactly result in what's whished. Even though the animated flag is false, you can shortly see the dismissal before the Details View is pushed :/
– vomi
Jan 2 at 17:57
have you tried doing the dismissal in a completion block of the presentation?
– FJ de Brienne
Jan 2 at 17:58
have you tried doing the dismissal in a completion block of the presentation?
– FJ de Brienne
Jan 2 at 17:58
|
show 3 more comments
0
active
oldest
votes
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%2f53985768%2fmaster-detail-view-from-add-view-to-detail-view-and-vice-versa%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53985768%2fmaster-detail-view-from-add-view-to-detail-view-and-vice-versa%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
Why not segue to the details when the Save button is pressed? What have you tried?
– FJ de Brienne
Dec 31 '18 at 13:35
Because it does not animate as it does in the Contacts app when you add a new contact
– vomi
Dec 31 '18 at 16:19
In the contacts app, the Add Contact screen is presented modally. When a contact is added, the Contact Details screen for the newly added Contact are pushed in the UINavigationController stack. You can do the same thing using a completionBlock on the dismissal of the modally presented View Controller, no?
– FJ de Brienne
Dec 31 '18 at 20:06
That's the idea, but doing so does not exactly result in what's whished. Even though the animated flag is false, you can shortly see the dismissal before the Details View is pushed :/
– vomi
Jan 2 at 17:57
have you tried doing the dismissal in a completion block of the presentation?
– FJ de Brienne
Jan 2 at 17:58