英文:
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时,NewTable
的create
函数不会被调用。只有在点击后,我才会在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
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.
[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…
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论