TableView中URL的图像

时间:2011-05-30 02:16:49

标签: iphone uitableview nsstring nsdata

我在tablview中放置图片时遇到问题。现在,由于我没有收到任何错误或警告信息,因此我将所有内容编码为正确,当我在模拟器中运行时观察转储时,您可以清楚地看到它在您向上和向下滚动时加载图像并且在单元格本身中所有内容都被推送像它准备好了那个图像,但仍然没有去!

所以这是我正在使用的代码行 -

注意:“avatarsURL”是一个MutableArray,如果我尝试将其更改为其他任何内容,但它会给我一个标志警告,指出与字符串不兼容的指针.....

在这个标题中,“avatarsURL”是一个MutableArray,但是来自NSDictionary的另一个.H文件中的NSString。

 NSString *imageurl = [avatarsURL objectAtIndex:0]; 
 NSLog(@"http://a0.twimg.com/profile_images/1268205919/iDD_normal.png");   
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL   
URLWithString:imageurl]]; 
UIImage *tableImage = [[UIImage alloc] initWithData:imageData]; 

[cell.imageView setImage:tableImage]; 
//cell.imageView.image = tableImage;//Another Method I was trying but same thing
CGSize imageSize = CGSizeMake(75,75);   
UIGraphicsBeginImageContext(imageSize); 
CGRect imageRect = CGRectMake(0.2, 0.1, imageSize.width, imageSize.height); 
[tableImage drawInRect:imageRect]; 
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();       

我使用了一个已知的http:// .image用于测试目的,因此我知道它不是服务器或实际调用的是JSON请求

任何建议都会非常感谢!没有任何转储,错误或警告,我完全迷失了。希望很快能收到某人的消息,

谢谢!!!

原始NSLog转储 我只能显示两个链接,因为我是一个新成员和垃圾邮件的原因...但你明白这可以继续下去!它会加载大约30开始,然后滚动时显示其余部分!

2011-05-29 22:02:37.940 ThemeCatcher[6463:207]    
http://a0.twimg.com/profile_images/1268205919/iDD_normal.png
2011-05-29 22:02:37.957 ThemeCatcher[6463:207] 
http://a0.twimg.com/profile_images/1268205919/iDD_normal.png

并且在下面提供的NSLog中它执行相同的操作,但不是链接,而是显示NULL

2011-05-29 22:08:04.368 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.369 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.370 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.371 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.372 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.373 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.374 ThemeCatcher[6503:207] (null)
2011-05-29 22:08:04.375 ThemeCatcher[6503:207] (null)

UPDATE!〜!!!

AWNSER

EXPLANATION~在你的NSDictionary中确保你使用下面的内容,因为用户是一个对象词典......

在一个子类中制作

NSObject {

NSDictionary * YourDictionary

}

然后

- (NSString *)yourStrings;

然后在.m文件中为您的用户头像创建您的字符串字典,如下所示!

-(NSString*)avatarURL {

return [[contents objectForKey:@"user"] objectForKey:@"profile_image_url"];



}

现在这是我如何将图像添加到单元格中!幸福编码至少现在在WEB上有一些解决方案!!!

 NSURL *url = [NSURL URLWithString:[(Tweet*)[avatarsURL    
 objectAtIndex:indexPath.row]avatarURL]];
 NSData *data = [NSData dataWithContentsOfURL:url];
// NSLog(@"http://a0.twimg.com/profile_images/1268205919/iDD_normal.png");//Done Loging  
 UIImage *tableImage = [[UIImage alloc] initWithData:data]; 
 [cell.imageView setImage:tableImage]; 
 cell.imageView.image = tableImage ;
 CGSize imageSize = CGSizeMake(45,45);  
 UIGraphicsBeginImageContext(imageSize); 
 CGRect imageRect = CGRectMake(0.2, 0.1, imageSize.width, imageSize.height); 
 [tableImage drawInRect:imageRect]; 
  cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
 UIGraphicsEndImageContext();    

0 个答案:

没有答案
相关问题