Fyne表格初始时不显示数据。

huangapple go评论92阅读模式
英文:

Fyne Table not showing data initially

问题

我有一个Fyne表格,我正在用数据填充它。

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

var transactions []transaction

func init() {// 数据填充被省略 }

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

当窗口初始显示时,表格没有数据。

如果我点击任何单元格,数据就会填充。

我已经通过调试器运行了这个代码,并发现当创建UI时,NewTablecreate函数不会被调用。只有在点击后,我才会在create函数中断点。

[更新]
这个问题是一个已知的bug,可以在以下链接中找到相关信息:https://github.com/fyne-io/fyne/issues/3198 和 https://github.com/fyne-io/fyne/issues/3034

英文:

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
Fyne表格初始时不显示数据。

If I click in any cell, the data populates
Fyne表格初始时不显示数据。

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.

[Update]
This issue is a known bug and is referenced at https://github.com/fyne-io/fyne/issues/3198 and https://github.com/fyne-io/fyne/issues/3034.

答案1

得分: 0

听起来这应该在GitHub的错误跟踪器中列出,而不是在这里...

英文:

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

huangapple
  • 本文由 发表于 2022年8月8日 03:38:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/73270507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定