0

I am parsing a XML-File with NSXMLParser. The number of cells depends on how many entries the XML-File has. This all works fine.

Now I added an UIImageView to my Prototype Cell, in which I'd like to load my URL (declared in the XML-File).

My Storyboard Error: Couldn't compile connection..

I know it's due to the Prototype Cell. But how can I add a UIImageView to all Cells, where different images from XML can be displayed?

EDIT:

Heres my Code, but this is not important.. every time I connect the UIImageView in Interface Builder, the error shows up..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"productCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

XMLProductView *listedProduct = [appDelegate.products objectAtIndex:indexPath.row];

/*
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] init];
[queue addOperation:operation];
*/

NSString *imageURL = listedProduct.image;

NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]];

UIImage *image = [UIImage imageWithData:imageData];

[imageView setImage:image];

cell.textLabel.text = listedProduct.name;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;

}

filou
  • 1,609
  • 5
  • 26
  • 53

1 Answers1

1

Maybe your imageView is an outlet? It should not be wired to a Prototype cell. You can add the imageView in program:

 [cell addSubview:imageView];

or create the imageView in storyboard and get it through:

 [cell viewWithTag:theTagOfImageView];

Edit 2

I think it is really what you need. Good luck!

LazyTableImages

lu yuan
  • 7,207
  • 9
  • 44
  • 78
  • thank you lu for your answer. I tried both but nothing works.. I checked some posts here on SO and found this:http://stackoverflow.com/questions/9693595/cant-compile-connection-ios5. But I am not sure if it works. – filou May 31 '12 at 19:44
  • @AlexisW I think it should work. As i do it this way without problem. plz check more carefully, and put the code which you have tried:) – lu yuan May 31 '12 at 19:47
  • okay lu, I tried this code: `UIImageView *imageView2 = (UIImageView *)[cell viewWithTag:1];` and `imageView2.image = image;`. But nothing works .___.'' – filou May 31 '12 at 20:16
  • @AlexisW plz put some code in your answer and tell me what's "nothing works"? – lu yuan Jun 01 '12 at 04:31
  • Hi lu, code is in there? my problem: the image does not get shown. – filou Jun 01 '12 at 04:34
  • @AlexisW ok, no "Couldn't compile connection.." right? Now, you should do something when your image is downloaded. Detail plz check the LazyTableImage sample code. I will put the download link in my answer. – lu yuan Jun 01 '12 at 04:43
  • the code is quite another way than I'd like to solve this problem. Everything works fine expect this imageview. I cannot change my whole code for this. – filou Jun 01 '12 at 05:07
  • @AlexisW The principle is similar – lu yuan Jun 01 '12 at 07:05
  • hey lu, I found the error: as shown in your link and I don't need to set an UIImageView to the prototype cell. for me it's made with `cell.imageView.image = image;` without an out-pointing reference. thank you :) – filou Jun 01 '12 at 09:45