Objective C 线程,在 iOS tableViewCell 中设置图像
我刚刚开始使用线程,并且试图从应用程序中的 TableView 获得更好的性能。每个tableViewCell都有一个imageView,并且在创建tableViewCell时从磁盘加载图像。我想在不同的线程上加载图像,然后在主线程上设置 UIImageView 。我的问题是,在另一个线程上运行的方法可以向主线程返回值吗?有更好的方法来做到这一点吗?
感谢您提前提供的任何帮助。
I've just started using threads and I'm trying to get better performance from my TableView in my app. Each tableViewCell has an imageView and the image is loaded from disk when the tableViewCell is created. I want to load the Image on a differant thread, then set the UIImageView on the main thread. My question is, can a method that is being ran on another thread return a value to the main thread? Is there a better approach for doin this?
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许是这样的,假设您的图标位于文档的目录中:
您将需要跟踪正在加载图像的单元格,这样您就不会在图像已经加载时尝试加载它。可能有一些小的语法错误,因为我没有编译它,只是徒手写的。
icons
是一个NSMutableArray
,为每个单元格保存一个 UIImagemaybe something like this, assuming your icons are in the document's directory:
you will need to keep track of which cells you are loading an image for, so you dont try to load one while it is already loading it. there may be some small syntax errors as i did not compile this, just wrote it freehand.
icons
is anNSMutableArray
holding a UIImage for each cell试试这个:
https://github.com/foursquare/full-loaded
Try this:
https://github.com/foursquare/fully-loaded
是的,您可以将数据传递到主线程。请参阅 NSObject API 文档:
您可以在
arg
参数中传递单个对象引用。Yes, you can pass data to the main thread. See the following method in NSObject API docs:
You get to pass a single object reference in the
arg
parameter.