【发布时间】:2016-05-12 15:00:26
【问题描述】:
谁能告诉我它不会在模拟器中隐藏我的 UIView? 该代码正在运行,它会打印我添加到函数中的数字,但它仍然不起作用。
基本上我想点击单元格,单元格中的 grayView 应该会消失。
override func viewDidLoad() {
super.viewDidLoad()
let lpgr = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap(_:)))
lpgr.numberOfTapsRequired = 1
lpgr.delaysTouchesBegan = true
lpgr.delegate = self
AlarmCollection.addGestureRecognizer(lpgr)
}
// MARK: UICollectionViewCell
func handleTap(gestureReconizer: UITapGestureRecognizer) {
if gestureReconizer.state != UIGestureRecognizerState.Ended {
return
}
let p = gestureReconizer.locationInView(AlarmCollection)
let indexPath = AlarmCollection.indexPathForItemAtPoint(p)
if let index = indexPath {
var cell = AlarmCollection.cellForItemAtIndexPath(index)
// do stuff with your cell, for example print the indexPath
print(index.row)
updateView(indexPath!)
} else {
print("Could not find index path")
}
}
func updateView(indexPath: NSIndexPath) {
let cell = AlarmCollection.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! AlarmItemCell
cell.greyView.hidden = true
print("2")
}
编辑:
// MARK: UICollectionViewCell
func handleTap(gestureReconizer: UITapGestureRecognizer) {
if gestureReconizer.state != UIGestureRecognizerState.Ended {
return
}
let p = gestureReconizer.locationInView(AlarmCollection)
let indexPath = AlarmCollection.indexPathForItemAtPoint(p)
if let index = indexPath {
var cell = AlarmItemCell()
// do stuff with your cell, for example print the indexPath
print(index.row)
updateView()
} else {
print("Could not find index path")
}
}
func updateView(cell: UICollectionViewCell) {
if let cell = cell as? AlarmItemCell {
cell.greyView.hidden = true
}
print("2")
}
编辑 2:
if let index = indexPath {
let cell = AlarmCollection.cellForItemAtIndexPath(index)
updateView(cell!)
}
【问题讨论】:
-
你应该在发布之前清理你的代码。保留像
didReceiveMemoryWarning()这样不必要的代码和像//Do additional setup after loading...这样不需要的 cmets 会使阅读变得更加困难,并且可能会带走愿意提供帮助的人。也许你可以编辑你的帖子? -
好的,谢谢。
标签: xcode swift uicollectionview cell