3 раздела tableView с пользовательскими секциями Cell Segues swift

Итак, я пытаюсь иметь 3 разных сегмента с 3 разными ячейками раздела в табличном представлении. Я получаю начальное табличное представление для заполнения пользовательскими данными ячейки, но у меня возникают проблемы с настройкой каждой ячейки для перехода к каждому соответствующему новому 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

        }
    }

person user3708224    schedule 27.07.2015    source источник


Ответы (2)


вы можете проверить indexPath.section в методе делегата didSelectRowAtIndexPath:, например,

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
}
person Akhilrajtr    schedule 27.07.2015

Что вы сделали, так это то, что когда вы щелкаете по своей ячейке, она вызывает метод didSelectRow, и там вы указали только один переход и никаких условий для выполнения какого перехода. Поэтому вам нужно добавить условие if или switch, как сказал Ахилрайтр.

person Parth Adroja    schedule 27.07.2015