我有两节课。每当我得到文本字段的值时,它都不会打印任何内容,如果我摆脱了解包符号,它会打印出可选的(“”)。我该如何解决这个问题?
这是我的代码:
class userRegistration: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
// in faction cell for item at index path i have this code
function collectionView(..){
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellid", for: indexPath) as! registerNewUser
cell.registerButton.addTarget(self, action: #selector(click), for: .touchUpInside)
return cell
}
@objc func click()
{
let object = registerNewUser()
let email = object.newEmailTextField.text!
print(email)
}
}
这是以编程方式在Swift 4中完成的。
答案 0 :(得分:0)
您必须Indexpath
item
点击Register
Button
。
@objc func click(sender: UIButton)
{
let cellPosition = sender.convert(CGPoint.zero, to: collexnVw)
let indPath : IndexPath = collexnVw.indexPathForItem(at: cellPosition!)!
let cell = collxnVw.cellForItem(at: indPath) as! registerNewUser
let email = cell.newEmailTextField.text!
print(email)
}
您可以从此link
获得一些参考