Swift : Auto Text in Shinobi Grid


#1

I’m new in IOS programming, i working with Shinobi Data Grid but i get a little problem because the Swift example orr question about Shinobi is very hard to find. Below my snippet code :

    grid = ShinobiDataGrid(frame: self.view.bounds)
    grid?.frame = CGRect(x: 0, y: 120, width: (screenWidth), height: 600)
    
    theme = SDataGridTheme()
    theme?.iOS7Arrows = true
    theme?.hideVerticalGridlines = false
    grid?.apply(theme)
    
    self.view.addSubview(grid!) 
    .........
     
   addColumn(grid!, title: "Floor", width: 100, alignment: .right, 
   alignmentHeader: .right)

    grid?.numberOfFrozenColumns = 2
    grid?.layer.borderWidth = 1
    
    grid?.defaultCellStyleForHeaderRow.backgroundColor = UIColor(hex: "#1A237E")
    grid?.defaultCellStyleForHeaderRow.textColor = UIColor.white
    grid?.defaultCellStyleForHeaderRow.font.withSize(5)
    
    grid?.dataSource = self
    grid?.delegate = self
    ........
     
   func shinobiDataGrid(_ grid: ShinobiDataGrid!, prepareCellForDisplay cell: SDataGridCell!) {
    let textCell = cell as! SDataGridTextCell
    
     //        let textCell = cell as! SDataGridMultiLineTextCell
    var dataRow: [AnyHashable: Any]?
    
    dataRow = filteredDataRoomingList?[cell.coordinate.row.rowIndex] as? [AnyHashable: Any]
    
    textCell.sizeToFit()
    
    if (searchBarActive) {
        dataRow = filteredSearchDataRoomingList?[cell.coordinate.row.rowIndex] as? [AnyHashable: Any]
    }
    else {
       dataRow = filteredDataRoomingList?[cell.coordinate.row.rowIndex] as? [AnyHashable: Any]
    }
    
    if textCell.coordinate.column.tag == 0 {
        textCell.textField.text = (String(dataRow?["floor"] as! Int))
    //            gridMultiLine.textLabel.text = (String(dataRow?["floor"] as! Int))
        
           }
   }

I want my cell show the full text inside its content(wrap content) not truncate the text with … .

I read this , this but its not in Swift and i get the error :
Index out of range

Any suggest and answer will help for me. Thanks in advance


#2

Hi MrX,

It looks like you’ve posted this on StackExchange as well at http://stackoverflow.com/questions/43859593/swift-auto-text-in-shinobi-grid, where you also posted a solution, so I’m going to paste your solution code in here in case it helps other users:

func addColoumn(_ grid: ShinobiDataGrid, title: String, width: CGFloat, tag: Int, alignment: NSTextAlignment) {

    let screenSize = UIScreen.main.bounds
    let screenWidthInt = screenSize.width - CGFloat(arc4random_uniform(UInt32(screenSize.width)))

    let column = SDataGridColumn(title: title, cellType: SDataGridMultiLineTextCell.self)
    column?.width = (Int(screenWidthInt / width) as NSNumber) /*width as NSNumber!*/
    column?.tag = tag
    column?.cellStyle.textAlignment = alignment
    column?.headerCellStyle.textAlignment = alignment

    grid.addColumn(column)

}

func shinobiDataGrid(_ grid: ShinobiDataGrid!, prepareCellForDisplay cell: SDataGridCell!) {
    let dataCell = cell as! SDataGridMultiLineTextCell
    if cell.coordinate.column.tag == 0 {

        dataCell.sizeToFit()
        dataCell.textLabel.text = "msadimfodvnuonvosvndvdivndlvsndvmvnlcvnoidn odnosdvk odkmvosdk sodimdokvs kmdsdokv "

    }
    if cell.coordinate.column.tag == 1 {

        dataCell.sizeToFit()
        dataCell.textLabel.text = "msadimfodvnuonvosvndvdivndlvsndvmvnlcvnoidn odnosdvk odkmvosdk sodimdokvs kmdsdokv sdmfdfkm sdlfkdmlf dosfod domdso os "

    }
}

Please do get in touch if you have any further questions!

Regards,

Alison


#3

Hi aclarke,

Sorry for not share my solution in here, and thanks to help sharing answer in this question.