简体   繁体   中英

Fyne Table not showing data initially

I have a Fyne table that I am populating with data

type transaction struct {
    Name   string
    Amount float64
    Date   time.Time
    Memo   string
}

var transactions []transaction

func init() {// Data population omitted }

func makeCenter() *fyne.Container {
    table := widget.NewTable(
        func() (int, int) {
            return len(transactions), 4
        },
        func() fyne.CanvasObject {
            return widget.NewLabel("wide content")
        },
        func(i widget.TableCellID, o fyne.CanvasObject) {
            switch i.Col {
            case 0:
                o.(*widget.Label).SetText(transactions[i.Row].Name)
            case 1:
                o.(*widget.Label).SetText(transactions[i.Row].Date.Format(YYYYMMDD))
            case 2:
                o.(*widget.Label).SetText(fmt.Sprintf("%.2f", transactions[i.Row].Amount))
            case 3:
                o.(*widget.Label).SetText(transactions[i.Row].Memo)
            }
        },
    )
    table.SetColumnWidth(0, 200)
    table.SetColumnWidth(1, 100)
    table.SetColumnWidth(2, 100)
    table.SetColumnWidth(3, 300)
    split := container.NewHSplit(makeLeftSidebar(), table)
    split.Offset = 0.2
    return container.NewMax(split)
}

When my window initially is displayed, the table has no data在此处输入图像描述

If I click in any cell, the data populates在此处输入图像描述

I have run this through the debugger and have found that the NewTable 's create function does not get called when the UI is created. Only after a click do I get a break in the create function.

Sounds like something that should be listed in the bug tracker on GitHub rather than here…

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM