Lua wax實現列表上拉 下拉重新整理

2021-06-20 07:23:37 字數 4619 閱讀 3980

--

-- 定義類

--waxclass}

---- 初始化

--function init(self)

self.super:init()

self.states = {} --

-- loaddata(self)

self.loadingmore = false

self.page = 1

return self

end--

-- 頁面載入

--function viewdidload(self)

self:tableview():setdatasource(self)

self:tableview():setdelegate(self)

self:settitle("導航標題")

self:createtablefooter()

-- 新增下拉事件(ios6新特性)

-- self:setrefreshcontrol(uirefreshcontrol:init())

-- self:refreshcontrol():addtarget_action_forcontrolevents(self, "refreshtable", uicontroleventvaluechanged)

end--

----

function numberofsectionsintableview(self, tableview)

return 1

end--

----

function tableview_numberofrowsinsection(self, tableview, section)

return #self.states

end--

-- 調整tableview的大小

-- self:tableview():setframe(cgrect(0, 20, 320, 400))

end--

----

function tableview_cellforrowatindexpath(self, tableview, indexpath)

local identifier = "tableviewcell"

local cell = tableview:dequeuereusablecellwithidentifier(identifier)

cell = cell or uitableviewcell:initwithstyle_reuseidentifier(uitableviewcellstyledefault, identifier)

local record = self.states[indexpath:row() + 1];

local myimage =uiimage:imagewithdata(nsdata:datawithcontentsofurl(nsurl:urlwithstring(image_file)));

cell:imageview():setimage(myimage)

return cell

end--

-- 重新整理觸發的事件

--function refreshtable(self)

self:refreshcontrol():setattributedtitle(nsattributedstring:alloc():initwithstring("重新整理中..."));

puts("refresh_tablerefresh_tablerefresh_tablerefresh_tablerefresh_tablerefresh_table")

self:performselector_withobject_afterdelay("loaddata", nil, 2.0);

end--

----

function tableview_didselectrowatindexpath(self, tableview, indexpath)

tableview:deselectrowatindexpath_animated(indexpath, true)

end--

----

function scrollviewdidenddecelerating(self)

puts("scrollviewdidenddecelerating")

end-- 獲取列表資料

function loaddata(self, nextpage)

-- self:refreshcontrol():endrefreshing()

-- self:refreshcontrol():setattributedtitle(nsattributedstring:alloc():initwithstring("下拉重新整理"))

-- 建立**底部

-- function loaddatabegin(self, nextpage)

puts(nextpage)

if not self.loadingmore then

self.loadingmore = true

local tablefooteractivityindicator = uiactivityindicatorview:initwithframe(cgrect(75.0, 10.0, 20.0, 20.0));

tablefooteractivityindicator:setactivityindicatorviewstyle(uiactivityindicatorviewstylegray);

tablefooteractivityindicator:startanimating()

self:tableview():tablefooterview():addsubview(tablefooteractivityindicator);

self:loaddata(nextpage)

endend--

-- 載入資料完畢

-- function loaddataend()

self.loadingmore = false;

self:createtablefooter()

end--

-- 建立**底部

-- function createtablefooter(self)

self:tableview():settablefooterview(nil)

local tablefooterview = uiview:initwithframe(cgrect(0.0, 0.0, self:tableview():bounds().width, 40.0))

local loadmoretext = uilabel:initwithframe(cgrect(0.0, 0.0, 116.0, 40.0))

loadmoretext:setcenter(tablefooterview:center())

loadmoretext:setfont(uifont:fontwithname_size("helvetica neue", 14.0))

loadmoretext:settext("上拉顯示更多資料")

tablefooterview:addsubview(loadmoretext)

self:tableview():settablefooterview(tablefooterview)

end--

-- 滾動式觸發

-- function scrollviewdidenddragging_willdecelerate(self, decelerate)

puts("scrollviewdidenddragging_willdecelerate")

local table_y = self:tableview():contentoffset().y

local table_h = self:tableview():contentsize().height

local frame_h = self:tableview():frame().height

print(self.loadingmore, table_y, table_h, frame_h, "((not self.loadingmore) and (table_y > (table_h - frame_h)))=="..tostring(((not self.loadingmore) and (table_y > (table_h - frame_h)))))

-- 上拉到底部重新整理

if((not self.loadingmore) and (table_y > (table_h - frame_h))) then

self:loaddatabegin(true)

end-- 下拉到頂部重新整理

if((not self.loadingmore) and table_y < -5 ) then

self:loaddatabegin(false)

endend

上拉下拉功能 GPIO的上拉下拉功能說明

2011 07 11 14 36 394人閱讀 收藏舉報 the port pull up register controls the pull up resister enable disable of each port group.when the corresponding bit is 0...

上拉下拉電阻總結

一 定義 上拉就是將不確定的訊號通過乙個電阻嵌位在高電平!電阻同時起限流作用!下拉同理!上拉是對器件注入電流,下拉是輸出電流 弱強只是上拉電阻的阻值不同,沒有什麼嚴格區分 對於非集電極 或漏極 開路輸出型電路 如普通閘電路 提公升電流和電壓的能力是有限的,上拉電阻的功能主要是為集電極開路輸出型電路輸...

上拉下拉電阻的作用

在數位電路中不用的輸入腳都要接固定電平,通過1k電阻接高電平或接地。1.電阻作用 l 接電組就是為了防止輸入端懸空 l 減弱外部電流對晶元產生的干擾 l 保護cmos內的保護二極體,一般電流不大於10ma l 上拉和下拉 限流 l 1.改變電平的電位,常用在ttl cmos匹配 2.在引腳懸空時有確...