我正在使用默认的 UITableViewCell 。我想从本地服务器在单元格上设置图像...cell.imageView.image

发布于 2024-09-27 22:21:55 字数 1213 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怕倦 2024-10-04 22:21:55

回溯会有所帮助。哪里崩溃了?

我立即看到的问题是,您在远程加载时转义了 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, if urlString happens to be nil, you'll get a crash when you try to convert it to create the NSURL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文