I have an array of URL of images, and i want to display the image of each URL on a separate cell of the UITableView. In my previous code i used:
UIImageView *view_Image = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, 400, 180)];
view_Image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arrURL[i]]]];
This was inside a for loop such that the values of x,y and i would change for every UIImageView. However this approach does not work when i use this in cellForRowAtIndexPath. The images are not getting displayed, my implementation for cellForRowAtIndexPath is as:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *simpleIdentifier = @"simpleIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleIdentifier];
}
cell.textLabel.text = _arrNames[indexPath.row];
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 300, 150)];
imv.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arr[i]]]];
[cell.contentView addSubview:imv];
return cell;
}
Also when i directly add the URL of the image, the image is displayed in every row but the scrolling lags a lot. Any help will be appreciated. Thanks.