我有一个 TableView,在 UITableViewCell 中我有一个 UICollectionView。 现在在我的 collectionView 中,对于每个 collectionViewCell 都有一个创建单元格和删除单元格按钮选项。因此,对于创建单元格,我必须使用 CreateViewController,对于删除按钮,我必须删除相应的 collectionViewCell。
import UIKit
class TableCollectionCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
//collectionView cell
collectionView!.register(UINib(nibName: "CreateGroupCell", bundle: nil), forCellWithReuseIdentifier: "CreateGroupCell")
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
//Collection View
extension TableCollectionCell : UICollectionViewDataSource ,UICollectionViewDelegateFlowLayout
{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CreateGroupCell", for: indexPath) as! CreateGroupCell
cell.groupName.text = ""
CreateCardView(viewCorner: cell.cardView)
if(0 == indexPath.row)
{
//cell.btnDotted.tag = indexPath.row
//cell.btnShare.tag = indexPath.row
cell.btnDotted.setImage(UIImage(named: "Info"), for: UIControlState.normal)
cell.btnShare.setImage(UIImage(named : "AddGroup"), for: UIControlState.normal)
}
else if(indexPath.row >= 1 && indexPath.row <= 3)
{
cell.btnDotted.isHidden = true
cell.btnShare.isHidden = true
cell.groupImage.image = UIImage(named: "group_dull_card.png")
}
else
{
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if ( 0 == indexPath.row) {
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 200, height: 150)
}
}
现在在我的 didSelectRow 方法中,如果 (indexPath.row == 0) 那么我必须选择 CreateViewController。
我怎样才能做到这一点?我也是委托(delegate)新手。
最佳答案
didSelectRow方法
if ( indexPath.row == 0)
{
self.storyboard?.instantiateViewControllerWithIdentifier("CreateViewControllerid") as! CreateViewController.
self.navigationController?.pushViewController(secondViewController, animated: true)
}
关于ios - 如何使用 Collection View 单元格转到下一个 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41095111/