什么时候选择了tableviewcell滚动collectionviewcell

时间:2018-12-21 09:31:30

标签: ios swift

我有collectionviewcell.collectionviewcell里面我使用了tableview。 当我从表格视图中选择单元格时,我需要滚动collectionviewcell。我已经水平使用了collectionview。怎么办?

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.mainquestionViewModel.numberOfSections()

    }


    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        let cell = verticalCollectionView.dequeueReusableCell(withReuseIdentifier: "NH_MainHeader", for: indexPath)as!  NH_MainHeader

        cell.tableView.dataSource = self

        cellTypes = [.NHCheckBoxCell, .NHRadioTypeCell, .NHSmileyTypeCell, .NHStarRatingTypeCell, .NHTextTypeCell,.NHDatePickerTypeCell]

        for type in cellTypes{
            cell.tableView.registerNibForCellClass(type.cellType().getClass())
        }


        cell.setReviewData(reviews:self.mainquestionViewModel.titleForHeaderInSection(atsection: indexPath.row))

        return cell
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return self.mainquestionViewModel.numberOfRowsIn(section: section)
    }


    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        let model = self.mainquestionViewModel.titleForHeaderInSection(atsection: indexPath.section)
        print(model.answerType)

        print(model.answerType?.rawValue)
        let c = model.answerType
        return c!.cellType().getHeight()
    }



    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

         let model = self.mainquestionViewModel.titleForHeaderInSection(atsection: indexPath.section)

        print(model.options)

        print(model.answerType)

        print(model.answerType?.rawValue)

        let c = model.answerType
        let cellClass = c?.cellType().getClass()
        print(cellClass)

        let optionModel = self.mainquestionViewModel.datafordisplay(atindex: indexPath)


        let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell


//      cell.setOptions(Options1:model.optionsModelArray[indexPath.section])

        cell.setOptions(Options1:self.mainquestionViewModel.datafordisplay(atindex: indexPath))

        cell.selectionStyle = .none
              return cell

    }


    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){


        let model = self.mainquestionViewModel.titleForHeaderInSection(atsection: indexPath.section)

        print(model.options)

        print(model.answerType)

        print(model.answerType?.rawValue)

        let c = model.answerType
        let cellClass = c?.cellType().getClass()
        print(cellClass)

        let optionModel = self.mainquestionViewModel.datafordisplay(atindex: indexPath)


        let cell = tableView.dequeueReusableCell(withIdentifier: (cellClass?.cellReuseIdentifier())!, for: indexPath) as! BaseCell




    }

如何滚动collectionviewcell。快速从collectionviewcell中单击tableviewcell

1 个答案:

答案 0 :(得分:1)

快捷键3

  self.collectionView?.scrollToItem(at: //scroll collection view to indexpath
                              NSIndexPath.init(row:(self.collectionView?.numberOfItems(inSection: sectionNumber))!-1, //get last item of self collectionview (number of items -1)
                                               section: sectionNumber) as IndexPath //scroll to bottom of current section
                            , at: UICollectionViewScrollPosition.bottom, //right, left, top, bottom, centeredHorizontally, centeredVertically
                            animated: true)