How to dismiss UICollectionViewController from button in UICollectionViewCell
I am making an onboarding screen, on the last screen I have a button that says "continue" and is supposed to dismiss the onboarding screen. The onboarding screen is a collection view controller with cells as each page. Please do not hesitate to ask for clarification I am don't know what else to add.
Thanks,
Edit
So I implemented user Francesco Deliro's answer, first problem was that I accidentally added the "delegate = self" into the viewDidLoad(). I fixed that but still the viewController does not dismiss.
My code is as follow in my viewController cell for item:
let loginCell = LoginCell()
loginCell.delegate = self
Here is the extension
extension TutorialViewController: LoginCellDelegate {
func didCompleteOnboarding() {
print("I should dimiss")
self.dismiss(animated: true, completion: nil)
}
Do I not need to call that function anywhere in the class just leave it outside the main class.
Edit 2
Here is how I connected my button action to the originial
@objc func continueTapped() {
...
continueButton.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .allowUserInteraction, animations: { [weak self] in
self?.continueButton.transform = .identity
let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
self?.window!.layer.add(transition, forKey: kCATransition)
self?.delegate?.didCompleteOnboarding()
}, completion: { (success) in
token = true
defaults.set(token, forKey: "DidSee")
})
}
ios swift uicollectionview uicollectionviewcell dismiss
add a comment |
I am making an onboarding screen, on the last screen I have a button that says "continue" and is supposed to dismiss the onboarding screen. The onboarding screen is a collection view controller with cells as each page. Please do not hesitate to ask for clarification I am don't know what else to add.
Thanks,
Edit
So I implemented user Francesco Deliro's answer, first problem was that I accidentally added the "delegate = self" into the viewDidLoad(). I fixed that but still the viewController does not dismiss.
My code is as follow in my viewController cell for item:
let loginCell = LoginCell()
loginCell.delegate = self
Here is the extension
extension TutorialViewController: LoginCellDelegate {
func didCompleteOnboarding() {
print("I should dimiss")
self.dismiss(animated: true, completion: nil)
}
Do I not need to call that function anywhere in the class just leave it outside the main class.
Edit 2
Here is how I connected my button action to the originial
@objc func continueTapped() {
...
continueButton.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .allowUserInteraction, animations: { [weak self] in
self?.continueButton.transform = .identity
let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
self?.window!.layer.add(transition, forKey: kCATransition)
self?.delegate?.didCompleteOnboarding()
}, completion: { (success) in
token = true
defaults.set(token, forKey: "DidSee")
})
}
ios swift uicollectionview uicollectionviewcell dismiss
add a comment |
I am making an onboarding screen, on the last screen I have a button that says "continue" and is supposed to dismiss the onboarding screen. The onboarding screen is a collection view controller with cells as each page. Please do not hesitate to ask for clarification I am don't know what else to add.
Thanks,
Edit
So I implemented user Francesco Deliro's answer, first problem was that I accidentally added the "delegate = self" into the viewDidLoad(). I fixed that but still the viewController does not dismiss.
My code is as follow in my viewController cell for item:
let loginCell = LoginCell()
loginCell.delegate = self
Here is the extension
extension TutorialViewController: LoginCellDelegate {
func didCompleteOnboarding() {
print("I should dimiss")
self.dismiss(animated: true, completion: nil)
}
Do I not need to call that function anywhere in the class just leave it outside the main class.
Edit 2
Here is how I connected my button action to the originial
@objc func continueTapped() {
...
continueButton.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .allowUserInteraction, animations: { [weak self] in
self?.continueButton.transform = .identity
let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
self?.window!.layer.add(transition, forKey: kCATransition)
self?.delegate?.didCompleteOnboarding()
}, completion: { (success) in
token = true
defaults.set(token, forKey: "DidSee")
})
}
ios swift uicollectionview uicollectionviewcell dismiss
I am making an onboarding screen, on the last screen I have a button that says "continue" and is supposed to dismiss the onboarding screen. The onboarding screen is a collection view controller with cells as each page. Please do not hesitate to ask for clarification I am don't know what else to add.
Thanks,
Edit
So I implemented user Francesco Deliro's answer, first problem was that I accidentally added the "delegate = self" into the viewDidLoad(). I fixed that but still the viewController does not dismiss.
My code is as follow in my viewController cell for item:
let loginCell = LoginCell()
loginCell.delegate = self
Here is the extension
extension TutorialViewController: LoginCellDelegate {
func didCompleteOnboarding() {
print("I should dimiss")
self.dismiss(animated: true, completion: nil)
}
Do I not need to call that function anywhere in the class just leave it outside the main class.
Edit 2
Here is how I connected my button action to the originial
@objc func continueTapped() {
...
continueButton.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .allowUserInteraction, animations: { [weak self] in
self?.continueButton.transform = .identity
let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
self?.window!.layer.add(transition, forKey: kCATransition)
self?.delegate?.didCompleteOnboarding()
}, completion: { (success) in
token = true
defaults.set(token, forKey: "DidSee")
})
}
ios swift uicollectionview uicollectionviewcell dismiss
ios swift uicollectionview uicollectionviewcell dismiss
edited Nov 12 at 16:42
asked Nov 11 at 20:16
Dadon El-Kadi
236
236
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use delegation, for example:
protocol YourCellDelegate: class {
func didCompleteOnboarding()
}
Then in your cell:
class CustomCell: UICollectionViewCell {
weak var delegate: YourCellDelegate?
// in your button action
func dismissAction() {
delegate.didCompleteOnboarding()
}
}
Finally in your view controller set the cell delegate in the cellForItem function:
yourCell.delegate = self
And add:
extension YourViewController: YourCellDelegate {
func didCompleteOnboarding() {
// dismiss here
}
}
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
|
show 14 more comments
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%2f53252815%2fhow-to-dismiss-uicollectionviewcontroller-from-button-in-uicollectionviewcell%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
You can use delegation, for example:
protocol YourCellDelegate: class {
func didCompleteOnboarding()
}
Then in your cell:
class CustomCell: UICollectionViewCell {
weak var delegate: YourCellDelegate?
// in your button action
func dismissAction() {
delegate.didCompleteOnboarding()
}
}
Finally in your view controller set the cell delegate in the cellForItem function:
yourCell.delegate = self
And add:
extension YourViewController: YourCellDelegate {
func didCompleteOnboarding() {
// dismiss here
}
}
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
|
show 14 more comments
You can use delegation, for example:
protocol YourCellDelegate: class {
func didCompleteOnboarding()
}
Then in your cell:
class CustomCell: UICollectionViewCell {
weak var delegate: YourCellDelegate?
// in your button action
func dismissAction() {
delegate.didCompleteOnboarding()
}
}
Finally in your view controller set the cell delegate in the cellForItem function:
yourCell.delegate = self
And add:
extension YourViewController: YourCellDelegate {
func didCompleteOnboarding() {
// dismiss here
}
}
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
|
show 14 more comments
You can use delegation, for example:
protocol YourCellDelegate: class {
func didCompleteOnboarding()
}
Then in your cell:
class CustomCell: UICollectionViewCell {
weak var delegate: YourCellDelegate?
// in your button action
func dismissAction() {
delegate.didCompleteOnboarding()
}
}
Finally in your view controller set the cell delegate in the cellForItem function:
yourCell.delegate = self
And add:
extension YourViewController: YourCellDelegate {
func didCompleteOnboarding() {
// dismiss here
}
}
You can use delegation, for example:
protocol YourCellDelegate: class {
func didCompleteOnboarding()
}
Then in your cell:
class CustomCell: UICollectionViewCell {
weak var delegate: YourCellDelegate?
// in your button action
func dismissAction() {
delegate.didCompleteOnboarding()
}
}
Finally in your view controller set the cell delegate in the cellForItem function:
yourCell.delegate = self
And add:
extension YourViewController: YourCellDelegate {
func didCompleteOnboarding() {
// dismiss here
}
}
edited Nov 11 at 20:48
answered Nov 11 at 20:31
Francesco Deliro
2,4372817
2,4372817
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
|
show 14 more comments
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
Works but the button isn’t working :( The button doesn’t press
– Dadon El-Kadi
Nov 11 at 21:13
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I need some more information to help you :/ You can ask a new question explaining what happens and showing some of your code.
– Francesco Deliro
Nov 11 at 21:55
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I solved it I had to make the button a lazy var -.- But I do have a question about your solution. Where do I call the method didCompleteOnBoarding() in the viewController
– Dadon El-Kadi
Nov 12 at 0:15
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
I have implemented everything as you said, however, I don't know what to do from there it doesn't seem to work.
– Dadon El-Kadi
Nov 12 at 4:08
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
It works. When you press the button the delegate call the function, and your view controller receive the callback, there you can implement the dismiss. Update your question and show me how are you implementing it in your code. ;)
– Francesco Deliro
Nov 12 at 7:35
|
show 14 more comments
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%2f53252815%2fhow-to-dismiss-uicollectionviewcontroller-from-button-in-uicollectionviewcell%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