0

I made a Dynamic UITableViewCell with an UImageView and an UILabel. enter image description here

I linked items to code, build it and it gave me this alarm:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x7ff657212ee0  <IBProxyObject: 0x7ff6572e5e30> => nationLabel => <IBUILabel: 0x7ff6572e2bd0>>

I've never worked with dynamic cells so probably it's a stupid mistake of mine, but I can understand the reason of it. How can I solve it? Thank you!

Matte.Car
  • 2,007
  • 4
  • 23
  • 41

1 Answers1

0

Sounds like you're trying to establish outlets from your prototype cell to your view controller. As mentioned in the comments, that isn't going to work because there are potentially multiple cells and they can't all be connected to the same outlet. So, the first thing you need to do is delete these outlet connections from the storyboard. Once you've done that, the code should compile. From there you have two options (well, I'm sure there are other ways to do this, but these are the normal ones):

  1. In the storyboard, set unique values for the tag property for each element, e.g. make the image 1 and the label 2. In your view controller, anytime you need to access an element, you can do so by calling [self.view viewWithTag:].

  2. Create a custom cell subclass of UITableViewCell, assign it to your prototype, and create outlets between the prototype and the subclass.

It sounds like you've tried (1) and got stuck. If you get stuck, just explain the specific issue you're having and someone will help you work it out.

Timothy Moose
  • 9,895
  • 3
  • 33
  • 44
  • Thank you! I chose first way and I solved in 2 row, amazing! – Matte.Car Aug 11 '13 at 12:50
  • I still got one trouble that I think it's easy to solve but I don't remember how: controller loads just visible rows so, scrolling, it shows blanks row and previous rows became blank... I wrote [tableView dequeueReusableCellWithIdentifier: @"cell" forIndexPath:indexPath] so it should be something else... – Matte.Car Aug 11 '13 at 12:56
  • If you're seeing blank rows, you need to check what's happening in `cellForRowAtIndexPath`. Set a breakpoint in that method or some `NSLog` statements and look for a) `dequeueReusableCellWithIdentifier` is actually returning a cell and b) the data you're using to configure the cell is not `nil`. – Timothy Moose Aug 11 '13 at 14:35
  • Cells work so cellForRowAtIndexPath method runs and return a cell, but cells which aren't displayed on startup don't work...now, I don't know why, scrolling down, it recharges previous cells; for example: on startup controller shows cells 1, 2, 3 and 4, scrolling down he will show again cells 1, 2, 3, and 4, same thing to the end... – Matte.Car Aug 11 '13 at 16:23
  • Cells get recycled. You've got to configure them in `cellForRowAtIndexPath` with the data for the given index path. – Timothy Moose Aug 11 '13 at 16:28
  • You might want to open a new question so you can post the relevant code. – Timothy Moose Aug 11 '13 at 16:29