How to get row and column from index?

前端 未结 4 650
南方客
南方客 2020-12-25 11:59

I\'m drawing a HUGE blank here.

Everything I\'ve found is about getting an index from a given row and column, but how do I get a row and a column from an in

4条回答
  •  粉色の甜心
    2020-12-25 12:12

    Swift 4

    typealias ColumnRowType = (column:Int, row:Int)
    
    func indexToColumnRow(index:Int, columns:Int) -> ColumnRowType
    {
        let columnIndex = (index % columns)
        let rowIndex = /*floor*/(index / columns)    // we just cast to an `Int`
    
        return ColumnRowType(columnIndex, rowIndex)
    }
    

提交回复
热议问题