iphone(UITableViewCell)动态加载图片
来源:互联网 发布:只有微信无法连接网络 编辑:程序博客网 时间:2024/05/21 18:14
iphone(UITableViewCell)动态加载图片
iphone开发 2010-12-22 09:31:16 阅读34 评论0 字号:大中小 订阅
官方的例子(支持3.x以上的机子)
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
其实在iphone上面是实现图片的动态加载,其实也不是很难,其中只要在代理中实现方法就可以
首先在头文件中声明使用到的代理 如
@interface XXX : UIViewController<UIScrollViewDelegate>
然后在.m中实现
//滚动停止的时候在去获取image的信息来显示在UITableViewCell上面
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[self loadImagesForOnscreenRows];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self loadImagesForOnscreenRows];
}
//
- (void)loadImagesForOnscreenRows
{
if ([self.entries count] > 0)
{
NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in visiblePaths)
{
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
if (!appRecord.appIcon) // avoid the app icon download if the app already has an icon
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
………//初始化UITableView的相关信息
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
………
if (!appRecord.appIcon)//当UItableViewCell还没有图像信息的时候
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)//table停止不再滑动的时候下载图片(先用默认的图片来代替Cell的image)
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
else//当appReacord已经有图片信息的时候直接显示
{
cell.imageView.image = appRecord.appIcon;
}
}
以上就是动态加载的主要的代码实现(其中不包括从网络上面下载图片信息等操作)
*************************************
因为我们创建UITableviewCell的时候是以重用的方式来创建,所以就相当于说第一屏显示的cell就是以后显示数据和图片的基础,因为后面数据超出一平的时候,我们只是改变数据的显示,并没有为每一个cell的数据元创建相应的一个
UITableViewCell(这样非常的浪费内存),要是我们没有实现
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
和
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
代理的时候,当我们滚动UITableView的时候TableView 就是按照顺序来加载图片的信息资源,这样当我们用力滚动Table的时候就感觉相当的卡,(其实UITableView实在一个个的显示出cell的信息)
当我们实现了以上代理的话,就可以实现在tableView滚动停止的时候,在去加载数据信息,这样滚动期间的tableViewCell就可以用默认的图片信息来显示了。
iphone开发 2010-12-22 09:31:16 阅读34 评论0 字号:大中小 订阅
官方的例子(支持3.x以上的机子)
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
其实在iphone上面是实现图片的动态加载,其实也不是很难,其中只要在代理中实现方法就可以
首先在头文件中声明使用到的代理 如
@interface XXX : UIViewController<UIScrollViewDelegate>
然后在.m中实现
//滚动停止的时候在去获取image的信息来显示在UITableViewCell上面
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[self loadImagesForOnscreenRows];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self loadImagesForOnscreenRows];
}
//
- (void)loadImagesForOnscreenRows
{
if ([self.entries count] > 0)
{
NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in visiblePaths)
{
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
if (!appRecord.appIcon) // avoid the app icon download if the app already has an icon
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
………//初始化UITableView的相关信息
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
………
if (!appRecord.appIcon)//当UItableViewCell还没有图像信息的时候
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)//table停止不再滑动的时候下载图片(先用默认的图片来代替Cell的image)
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
else//当appReacord已经有图片信息的时候直接显示
{
cell.imageView.image = appRecord.appIcon;
}
}
以上就是动态加载的主要的代码实现(其中不包括从网络上面下载图片信息等操作)
*************************************
因为我们创建UITableviewCell的时候是以重用的方式来创建,所以就相当于说第一屏显示的cell就是以后显示数据和图片的基础,因为后面数据超出一平的时候,我们只是改变数据的显示,并没有为每一个cell的数据元创建相应的一个
UITableViewCell(这样非常的浪费内存),要是我们没有实现
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
和
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
代理的时候,当我们滚动UITableView的时候TableView 就是按照顺序来加载图片的信息资源,这样当我们用力滚动Table的时候就感觉相当的卡,(其实UITableView实在一个个的显示出cell的信息)
当我们实现了以上代理的话,就可以实现在tableView滚动停止的时候,在去加载数据信息,这样滚动期间的tableViewCell就可以用默认的图片信息来显示了。
- iphone(UITableViewCell)动态加载图片
- iphone(UITableViewCell)动态加载图片
- iphone(UITableViewCell)动态加载图片
- iphone动态加载图片
- UITableViewCell 图片加载
- UITableViewCell加载图片
- iphone table 实现动态加载图片
- iphone table 实现动态加载图片
- iPhone UITableView异步加载图片 (动态加载图片)
- iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
- iPhone开发学习笔记——Xib设计UITableViewCell然后动态加载
- iPhone开发学习笔记002――Xib设计UITableViewCell然后动态加载
- iPhone开发学习笔记002——Xib设计UITableViewCell然后动态加载
- Iphone 图片设置阴影和动态加载图片
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- iPhone table 实现动态加载图片的教程
- sort命令
- android中google“定位查询”编辑
- 内存屏障: barrier()与mb()
- Android开发的技术层次
- 海量数据面试题整理 .
- iphone(UITableViewCell)动态加载图片
- Mesa安装手记--在Ubuntu 9.10
- 8B/10B编码理解
- 在 ocx 内部如何获取所在页面的 URL
- Ubuntu下OpenGL/Mesa3D配置
- asp表单提交两次问题
- iphone开发——获取汉字拼音
- 霍尼韦尔报警主机常见问题问答
- CSS控制表格隔行变色与鼠标滑过变色