ios - 3 tableView Sections with custom Cell Segues swift

标签 ios xcode swift segue custom-cell

所以我试图在表格 View 中使用 3 个不同的部分单元格创建 3 个不同的 segues。我正在获取初始表格 View 以填充自定义单元格数据,但无法将每个单元格设置为转至每个相应的新 ViewController...所以我想要 3 个具有 3 个不同转场的单元格...感谢您的帮助!

class ProfileTableViewController: UITableViewController {

 var tableData: [String] = ["milan", "parisTower", "alps_1-blur", "alps_1", "meStanding"]


        //register TravelBook Custom Cell
        let nib = UINib(nibName: "TravelBookCell", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: "TravelBookCell")
        self.tableView.dataSource = self

        }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        return 3
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if(section == 0) {
            return 1
        }
        if(section == 1) {
            return 1 
        }
        else {
            return tableData.count
        }

    }




    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        _ = tableView.cellForRowAtIndexPath(indexPath)
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        performSegueWithIdentifier("TravelBookDetailSegue", sender: TravelBookTableViewCell())
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {



    }



        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {



        switch indexPath.section{

        // 1st custom cell
        case 0:
            let myProfile = tableView.dequeueReusableCellWithIdentifier("ProfileHeaderCell") as! VideoTableViewCell

            myProfile.frame.size = CGSize(width: 600.0, height: 60.0)


            return myProfile




        // 2nd custom cell
        case 1:
            let myInfo = tableView.dequeueReusableCellWithIdentifier("AlbumCell") as! AlbumTableViewCell



            return myInfo 




          // 3rd Custom Cell
          default:
            let cell = tableView.dequeueReusableCellWithIdentifier("TravelBookCell") as! TravelBookTableViewCell

            cell.travelBookImage.image = UIImage(named: tableData[indexPath.row])
            cell.travelBookTitle.text = tableData[indexPath.row]

            return cell

        }
    }

最佳答案

你可以检查 didSelectRowAtIndexPath: 中的 indexPath.section 委托(delegate)方法,例如,

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    switch indexPath.section{

        case 0:
             //first segue
             break
        case 1:
             //second segue
             break
        case 2:
             //third segue
             break
}

关于ios - 3 tableView Sections with custom Cell Segues swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31645045/

相关文章:

ios - 为 tabbaritem 添加图像,但它不显示在 ios 中

c++ - 具有多个 cpp 文件的 Xcode 项目

xcode - 录音语义问题

ios - 如何从 NSDictionary 中删除空值

ios - 从应用内苹果获取productId-s列表

ios - UIScrollView 的委托(delegate)方法未触发

ios - 在 Swift 中将自定义输入 View 添加到 UITextField

arrays - 如何在 Swift 中刷新文件中的数组内容?

iphone - 如何使用 indexpath.row 从 UICollectionView 中删除项目

swift - 无法将类型 'Int' 的返回表达式转换为返回类型“Property<Int>”