当list设置为虚之后,快速滚动list,list内渲染的图片会消失,怎么解决这个问题

已邀请:

谷主

赞同来自:

测试demo。

lovegame

赞同来自:

你好, 我也遇到了这个问题, 请问解决了吗

lovegame

赞同来自:

QQ截图20200505163533.png

 

谷主

赞同来自:

你看看你是不是用了异步,异步的问题看教程怎么教的。

lovegame

赞同来自:

设置图片url 算异步操作吗, 就只是干了 这个啊

谷主

赞同来自:

贴render函数吧。

lovegame

赞同来自:

function ItemMediator:OnRenderItem(index, item)
    local data = self._listItemData[index + 1]
    item.data = data
    ---@type ItemUI
    local iconItem = item:GetChild("iconItem")
    if data == -1 then
        iconItem:SetItemId(-1)
        iconItem.text = ""
        local bagOpenSize = DataMgr.itemMgr:GetBagOpenSize()
        item:GetChild("imgLock").visible = index > bagOpenSize
        item:GetChild("boxTime").visible = index == bagOpenSize
        item:GetChild("imgNew").visible = false
        item:GetChild("txtForce").text = ""
    else
        iconItem:SetItemId(data.template)
        item:GetChild("imgLock").visible = false
        item:GetChild("boxTime").visible = false
        item:GetChild("imgNew").visible = false
        item:GetChild("txtForce").text = data.forceLv > 0 and string.format("+%s", data.forceLv) or ""
        local itemTemp = TempMgr.item:GetById(data.template)
        iconItem.text = itemTemp.maxCount > 1 and string.format("x%s", data.count) or "x1"
    end
end
 

lovegame

赞同来自:

function ItemUI:SetItemId(id)
    self.data = TempMgr.item:GetById(id)
    if self.data == nil then
        self:SetIcon(nil)
        self:SetQuality(0)
    else
        self:SetIcon(ItemUtils.Icon(id))
        self:SetQuality(self.data.quality)
    end
end
---设置图标
---@param icon string 路径
function ItemUI:SetIcon(icon)
    self._iconUrl = icon == nil and "" or icon
    self.icon = icon
    if icon == nil then
        if self._bgUrl ~= "" then
            self._bg.icon = self._bgUrl
        end
    else
        self._bg.icon = nil
    end
    log( LogType.BASE, "=====SetIcon=====", icon, self._bgUrl )
end
---设置图标背景图,
---@param url string 路径, 支持ui://
function ItemUI:SetBg(url)
    self._bgUrl = url == nil and "" or url
    self._bg.icon = url
end
---设置品质框, 0-6
---@param quality number
function ItemUI:SetQuality(quality)
    self.quality = quality
    self._qualityCtrl.selectedIndex = quality
end
 

谷主

赞同来自:

把render简化到一句话, xxx.icon="ui://xxx"这样子再测试

要回复问题请先登录注册