ios - 如何使用 Collection View 单元格转到下一个 View ?

标签 ios swift uitableview uicollectionview delegates

我有一个 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/

相关文章:

ios - 如何从 tableview 的每个部分中快速选择一行?

ios - 在 iPhone MPMoviePlayerController 上播放字节流

swift - 为使用 URLSession 和 RxSwift 的函数编写单元测试

ios - 添加附件后,自定义 UITableViewCell 的大小不正确

ios - 联系人信息样式 TableView

ios - 此类与键的键值编码不兼容...为什么?

ios - Flurry - 用户获取分析 (UAA) - 无安装

ios - Monotouch - UIViewController 内的 TableView : override functions don't get called

ios - 如何从 IOS 应用程序打开特定的 Facebook 帖子。不是 Facebook 页面。打开 Facebook 帖子的正确 url 方案?

swift - swift 将内存设置为 UnsafeMutablePointer<UInt8>