How to dismiss UICollectionViewController from button in UICollectionViewCell
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
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 |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
up vote
0
down vote
accepted
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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
up vote
0
down vote
accepted
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
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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,4292817
2,4292817
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