我在集合视图单元格中有名称和图像。我想获取我在单击该特定单元格中的复选框时选择的名称。我该怎么办?
以下是我在集合视图中的代码
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
<description>
Expects one of [nosasl, none, ldap, kerberos, pam, custom].
Client authentication types.
NONE: no authentication check
LDAP: LDAP/AD based authentication
KERBEROS: Kerberos/GSSAPI authentication
CUSTOM: Custom authentication provider
(Use with property hive.server2.custom.authentication.class)
PAM: Pluggable authentication module
NOSASL: Raw transport
</description>
</property>
这是我的手机文件:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath) as! MyCollectionViewCell
cell.imgView.sd_setImage(with: URL(string: str1+self.nameArr [indexPath.row]), placeholderImage: UIImage(named: ""))
cell.lblName.text = self.nameArr [indexPath.row]
cell.lblTime.text = self.timeArr [indexPath.row]
return cell
}
答案 0 :(得分:0)
您的CollectionView
class collectionVC: UIViewController,CellDelegate {
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath) as! MyCollectionViewCell
cell.imgView.sd_setImage(with: URL(string: str1+self.nameArr [indexPath.row]), placeholderImage: UIImage(named: ""))
cell.lblName.text = self.nameArr [indexPath.row]
cell.lblTime.text = self.timeArr [indexPath.row]
cell.checkButton.tag = indexPath.item
cell.delegateCell = self
cell.indexPath = indexPath
return cell
}
//Mark:- Did tap cell
func didTapCell(index: IndexPath){
let name = self.nameArr[index.item]
print("Your name >> \(name)")
}
}
收集单元
protocol CellDelegate: class {
func didTapCell(index: IndexPath)
}
class MyCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var checkButton: UIButton!
@IBOutlet var imgView: UIImageView!
@IBOutlet weak var lblName: UILabel!
@IBOutlet weak var lblTime: UILabel!
var delegateCell:CellDelegate?
var indexPath:IndexPath?
var tickCheck:Bool = false
@IBAction func btnCheck(_ sender: Any)
{
delegateCell?.didTapCell(index: indexPath!)
if tickCheck == false
{
checkButton.setBackgroundImage(UIImage(named: "check"), for: .normal)
tickCheck = true
}
else
{
checkButton.setBackgroundImage(UIImage(named: "uncheck"), for: .normal)
tickCheck = false
}
}
}