Auto scrolling to a cell with a specific value

后端 未结 4 1644
盖世英雄少女心
盖世英雄少女心 2020-12-14 09:06

I have a list of numbers in a table view like this.

\"enter

As you can see th

4条回答
  •  悲&欢浪女
    2020-12-14 09:36

    Do this to find the first element in the array that is equal to groupNoToScroll. Then, go to that row.

        var rowToGoTo:Int = 0 //Rather use the Swift find function.
        for x in items{
            if x == groupNoToScroll{
                break
            }
            rowToGoTo++
        }
    
        let lastRow = tableView.indexPathsForVisibleRows()?.last as NSIndexPath
        if indexPath.row == lastRow.row {
            if scrollToTime == true {
               let indexPath = NSIndexPath(row: rowToGoTo, section: 0)
               tblBusList.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
            }
        }
    

    But I would recommend doing this in viewDidAppear.

    As Isuru pointed out rather use the find function.

提交回复
热议问题