作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个入职屏幕,在最后一个屏幕上我有一个按钮,上面写着“继续”并且应该关闭入职屏幕。入职屏幕是一个 Collection View Controller ,每个页面都有单元格。请不要犹豫,要求澄清我不知道还要添加什么。
谢谢,
编辑所以我实现了用户 Francesco Deliro 的回答,第一个问题是我不小心将“delegate = self”添加到 viewDidLoad() 中。我修复了这个问题,但 viewController 仍然没有关闭。我的代码在项目的 viewController 单元格中如下所示:
let loginCell = LoginCell()
loginCell.delegate = self
这是扩展
extension TutorialViewController: LoginCellDelegate {
func didCompleteOnboarding() {
print("I should dimiss")
self.dismiss(animated: true, completion: nil)
}
我是否不需要在类中的任何地方调用该函数,只需将其留在主类之外即可。
编辑 2以下是我如何将按钮操作与原始按钮相关联
@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")
})
}
最佳答案
你可以使用委托(delegate),例如:
protocol YourCellDelegate: class {
func didCompleteOnboarding()
}
然后在你的单元格中:
class CustomCell: UICollectionViewCell {
weak var delegate: YourCellDelegate?
// in your button action
func dismissAction() {
delegate.didCompleteOnboarding()
}
}
最后,在您的 View Controller 中,在 cellForItem 函数中设置单元委托(delegate):
yourCell.delegate = self
并添加:
extension YourViewController: YourCellDelegate {
func didCompleteOnboarding() {
// dismiss here
}
}
关于ios - 如何从 UICollectionViewCell 中的按钮关闭 UICollectionViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53252815/
我是一名优秀的程序员,十分优秀!