您的位置:首页 > 理论基础 > 计算机网络

luat通过协程实现网络数据加载完毕后显示界面

2016-05-09 12:37 393 查看
function UIManager:openNetWindow( windowLayer, showBackground, showTopMenu, isMutexWindow, bgIndex )

self.netWindow = windowLayer
local co = coroutine.create( function()

windowLayer:retain()
NetManager:registerNet( windowLayer )
coroutine.yield( )

self:openWindow(  windowLayer, showBackground, showTopMenu, isMutexWindow, bgIndex )
windowLayer:release()
self.netWindow = nil
end)

windowLayer.co = co
function windowLayer:resume()
if self.co then
coroutine.resume( self.co )
self.co = nil
end
end

coroutine.resume( co )

end

运行过程:

1.直接运行coroutine.resume(co)这样协程由挂起状态切换为运行状态开始运行,碰到yield后挂起,等待数据返回。

2.通过windowLayer的resume方法,使得co又继续运行,显示,并且加载数据。

使用:

在init中发送请求的。不然,在enter中如果可以发送请求,那么要这个方法还有何用!enter一旦进入,就说明了这个界面已经显示出来了啊!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: