使用 UIImageView 上的 UIActivityIndicatorView 从 URL 加载图像
在我的 iPhone 应用程序中,我有一个 UITabelview,它通过 URL 填充数据。当我从 UITableview 中选择一个单元格时,它会调用 URL 并下载图像并传递到另一个 UITableview。当我单击单元格时,需要一段时间来加载图像并在 UITableviewcell 上保持单击状态。我有以下代码,它调用 URL 并在每次单元格调用时加载图像。
if (!cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"imageCell"] autorelease];
imageView1 = [[cell subviews] lastObject];
[cell addSubview:imageView1 ];
}
NSString fileName = image.Img;
NSString *filePath= [NSString stringWithFormat:@"http://www.abc.com/xml/id=12345",fileName];
UIImage *im = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:filePath]]];
subview = [[UIImageView alloc] initWithFrame:CGRectMake(120.0f, 10.0f,60.0f, 60.0f)] ;
[subview setImage:im];
[subview setContentMode:UIViewContentModeScaleToFill];
[cell.contentView addSubview:subview];
我见过很少有应用程序会下载个人资料图片并为其加载 UIActivityIndicator 数据。我想以同样的方式在 UIImageView 上使用 UIActivityIndicator 。任何人都可以帮助我在 uiimageview 上实现 uiactivityindicator 吗?
In my iphone application, I have a UITabelview which populates the data through URL. When I select one cell from UITableview, it calls the URL and downloads the image and pass on to another UITableview. When I click the cell it takes a while to load the image and stays clicked on UITableviewcell. I have the following code which calls the URL and loads the image on each cell call.
if (!cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"imageCell"] autorelease];
imageView1 = [[cell subviews] lastObject];
[cell addSubview:imageView1 ];
}
NSString fileName = image.Img;
NSString *filePath= [NSString stringWithFormat:@"http://www.abc.com/xml/id=12345",fileName];
UIImage *im = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:filePath]]];
subview = [[UIImageView alloc] initWithFrame:CGRectMake(120.0f, 10.0f,60.0f, 60.0f)] ;
[subview setImage:im];
[subview setContentMode:UIViewContentModeScaleToFill];
[cell.contentView addSubview:subview];
I have seen few apps where the profile pic is getting downloaded and have UIActivityIndicator loading in the data for it. I would like to use UIActivityIndicator on UIImageView in the same way. Can anyone help me out on achieving uiactivityindicator on uiimageview.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www.google.ru/search?q=iphone+load +图像+异步
http://www.google.ru/search?q=iphone+load+image+asynchronously