// delegate method that returns json
-(void)repaint:(NSMutableArray *)retrievedData
{
if (retrievedData.count > 0)
{
userObj = [retrievedData objectAtIndex:0];
for (userObj in retrievedData)
{
NSLog(@"%@is the value",retrievedData);
url_Img1=@"http://kiascenehai.pk/assets/uploads/event-images/50x50-thumb/";
url_Img2=userObj.event_dpURL;
url_Img_FULL = [url_Img1 stringByAppendingPathComponent:url_Img2];
NSLog(@"Show url_Img_FULL: %@",url_Img_FULL);
[tableData addObjectsFromArray:retrievedData];
[table reloadData];
}
}
}
//to display data in table:::
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]]];
答案 0 :(得分:0)
首先在接口部分全局创建一个NSMutableArray
并在viewDidLoad
方法中初始化
NSMutableArray *arr;
之后在url_Img_FULL
arr
[arr addObject:url_Img_FULL];
在cellForRowAtIndexPath
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]]];
到
[[cell imageView] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arr[indexPath.row]]]]];
同样在numberOfRowsAtIndexPath
return arr.count。
答案 1 :(得分:0)
Use GCD to download some thing like this
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
//write the code to download image
}
dispatch_async(dispatch_get_main_queue(), ^{
// Capture the indexPath variable, not the cell variable, and use that
[tableview reloadData];
});
});
and cellforrowatindexpath write
if(are.count>0)
{
[[cell imageView] setImage:[UIImage imageWithData:arr[indexPath.row]]]]];
}
return cell;