swift : Auto Text in Shinobi Grid

标签 swift datagrid shinobi

我正在使用 Shinobi Data Grid,但遇到了一些问题,因为很难找到有关 Shinobi Grid 的 Swift 示例或问题。下面是我的代码片段:

    var grid: ShinobiDataGrid?

    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))

           }
   }

我希望我的单元格显示其内容内的全文(换行内容)而不是用 .... 截断文本。

我读到this但我不知道这个 block ,因为它在 Objective C 中:

SDataGridColumn *nameColumn = [[SDataGridColumn alloc] initWithTitle:@"Forename" cellType:[SDataGridMultiLineTextCell class]];
nameColumn.editable = YES;
nameColumn.width = @250;
[self.shinobiDataGrid addColumn:nameColumn];

任何建议和答案都会对我有帮助。提前致谢

最佳答案

我制作了 this 的函数基础,在代码下面:

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)

}

数据源 prepareCellForDisplay 变成这样:

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 "

    }
}

enter image description here

关于 swift : Auto Text in Shinobi Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43859593/

相关文章:

swift - 在滚动时显示两次的最后一个 tableView 单元格中添加按钮

ios - fatal error : unexpectedly found nil while unwrapping an Optional value Computation

ios - 为什么在 Swift 中打印 NSMutableArray 对象时会显示 'identifier' 的模糊使用?

swift - 如何在 SwiftUI 中隐藏导航后退按钮?

wpf - 以编程方式选择并突出显示数据网格MVVM

ios - 图表中选定切片的颜色

ios - ShinobiCharts xAxis 标签被截断

wpf - DataGrid 排序升序 > 降序 > null(不排序)

Silverlight DataGridTextColumn 绑定(bind)可见性

ios - Nsmutablearray 在访问时损坏