我正在使用默认的 UITableViewCell 。我想从本地服务器在单元格上设置图像...cell.imageView.image
BLImageCache *sharedImageCache = [BLImageCache sharedInstance];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:indexPath ,@"IndexPath", nil] ;
NSString *urlString;
urlString = [[mNewsArray objectAtIndex:indexPath.row] objectForKey:@"imgUrl"];
urlString =[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
UIImage *image=[sharedImageCache imageForURL:urlString];
if(image==nil)
{
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[sharedImageCache loadImageFromURL:[NSURL URLWithString:urlString] sender:self context:(NSDictionary*)dictionary];
}
else{
cell.imageView.image =image;
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
应用程序崩溃了,任何人都可以告诉我我做错了什么,是否存在任何与内存相关的问题...
-(void)didLoadImage:(UIImage *)inImage contextInfo:(void *)inContext
{
if(inImage )
{
NSIndexPath *indexPath= [(id)inContext objectForKey:@"IndexPath"];
UITableViewCell *cell=[mTableView cellForRowAtIndexPath:indexPath];
inImage=[inImage resizeImagewithwidth:69 height:67];
cell.imageView.image=inImage;
}
}
BLImageCache *sharedImageCache = [BLImageCache sharedInstance];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:indexPath ,@"IndexPath", nil] ;
NSString *urlString;
urlString = [[mNewsArray objectAtIndex:indexPath.row] objectForKey:@"imgUrl"];
urlString =[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
UIImage *image=[sharedImageCache imageForURL:urlString];
if(image==nil)
{
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[sharedImageCache loadImageFromURL:[NSURL URLWithString:urlString] sender:self context:(NSDictionary*)dictionary];
}
else{
cell.imageView.image =image;
cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
The Application is crashing can Anyone tell me what I am doing wrong is there any Memory related Issue...
-(void)didLoadImage:(UIImage *)inImage contextInfo:(void *)inContext
{
if(inImage )
{
NSIndexPath *indexPath= [(id)inContext objectForKey:@"IndexPath"];
UITableViewCell *cell=[mTableView cellForRowAtIndexPath:indexPath];
inImage=[inImage resizeImagewithwidth:69 height:67];
cell.imageView.image=inImage;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回溯会有所帮助。哪里崩溃了?
我立即看到的问题是,您在远程加载时转义了
urlString
两次。另外,如果urlString
碰巧为零,当您尝试将其转换为创建NSURL
时,您会遇到崩溃。A backtrace would help. Where is it crashing?
The problems I can see immediately is that you are escaping
urlString
twice when loading remotely. Also, ifurlString
happens to be nil, you'll get a crash when you try to convert it to create theNSURL
.