【发布时间】:2015-12-23 18:32:55
【问题描述】:
我有一个用 Swift 编写的应用程序,它有一个集合视图,上面有一堆按钮。在页面顶部的导航栏中,我有一个密码文本框(有点像我在教程中看到的搜索框)。
当我切换开关时,我会收到与开关关联的项目的回调。我不知道如何访问从 UICollectionViewCell 输入的密码文本。下面是单元格的样子:
import UIKit
class GDCell: UICollectionViewCell {
weak var door: Door!
@IBOutlet weak var doorSwitch: UISwitch!
@IBOutlet weak var label: UILabel!
// ???HOW TO GET UITextField at the top of the page???
@IBAction func switchFlipped(sender: AnyObject) {
print("Switch flipped for \(door.id), locked is \(doorSwitch!.on)!")
var uri: String = "\(door.command_uri)\(doorSwitch!.on)"
print("Request: \(uri)")
print(self.contentView.classForCoder)
}
}
这是我在视图控制器中设置单元格的方式:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("GDCellId", forIndexPath: indexPath) as! GDCell
cell.door = doors![indexPath.item]
cell.label.text = "\(doors![indexPath.item].name)"
cell.doorSwitch.on = doors![indexPath.item].status == "Locked"
return cell
}
【问题讨论】:
标签: ios swift uicollectionview