需求是使用3个check
选中日 显示当日贡献
选中周 显示本周累计贡献
选中总 显示历史总数累计贡献
3个都不选中 则显示正常数据
--4种状态
NORMAL = 0
DAY = 1
WEEK = 2
TOTAL = 3
function UIHhMember:initCheck()
self.tbCheckList = {}
self.m_CheckBox_ConDay = g_seekWidgetByName(self._root,"m_CheckBox_ConDay")
self.m_CheckBox_ConWeek = g_seekWidgetByName(self._root,"m_CheckBox_ConWeek")
self.m_CheckBox_ConTotal = g_seekWidgetByName(self._root,"m_CheckBox_ConTotal")
self.tbCheckList[DAY] = self.m_CheckBox_ConDay
self.tbCheckList[WEEK] = self.m_CheckBox_ConWeek
self.tbCheckList[TOTAL] = self.m_CheckBox_ConTotal
local function conStateCallBack(sender,eventType)
local tag = sender:getTag()
if eventType == ccui.CheckBoxEventType.selected then
for k, v in ipairs(self.tbCheckList) do
if k ~= tag then
v:setSelected(false)
end
end
self:updateTbvData(tag)
elseif eventType == ccui.CheckBoxEventType.unselected then
self:updateTbvData(NORMAL)
end
end
self.m_CheckBox_ConDay:addEventListener(conStateCallBack)
self.m_CheckBox_ConWeek:addEventListener(conStateCallBack)
self.m_CheckBox_ConTotal:addEventListener(conStateCallBack)
self.m_CheckBox_ConDay:setTag(DAY)
self.m_CheckBox_ConWeek:setTag(WEEK)
self.m_CheckBox_ConTotal:setTag(TOTAL)
end
function UIHhMember:updateTbvData(_state)
print(_state)
if NORMAL == _state then
print("设置正常")
elseif DAY == _state then
print("设置日")
elseif WEEK == _state then
print("设置周")
elseif TOTAL == _state then
print("设置总")
end
end
网友评论