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一旦进入,就说明了这个界面已经显示出来了啊!
相关文章推荐
- http-web缓存
- 苹果文档“支持IPv6 DNS64/NAT64网络”的翻译(1)
- Bugtags,最适合移动应用的智能 Bug 管理系统
- 从网络获取数据(2)使用SyncAdapter
- OkHttp之Interceptors
- okhttp的第一次使用
- flux-retrofit-okhttp封装
- 大脑皮质网络中社区内和社区间同步与相关性的竞争|Competition between intra-community and inter-community synchronization...
- 常见HTTP状态码大全
- C#网络/检测某端口是否被占用的方法
- iOS 应用如何完全支持 IPv6-ONLY 网络?
- iis6.0发布站点,Http404错误解决方案
- 关于Content-Type的http请求头的格式
- HttpUrlConnection发送url请求(后台springmvc)
- apache.http.MalformedChunkCodingException: Chunked stream ended unexpectedly
- Cookie设置HttpOnly,Secure,Expire属性
- jar httpclient 少包,此处 区别 common-http包
- API23org.apache.http.NameValuePair 需要自己写入gradle的关联
- HttpClient例子
- 程序模拟HTTP请求