Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange error when adding items to prototype cells in storyboard-IB

I have quite a large project (~20 scenes). One of which is a TableViewController with a custom UITableViewController class. I have given the cell a reuse identifier, and added a label to it. When I try and Ctrl+Drag the label to the UITableViewController header file to create an outlet, I get the following error:

error: Illegal Configuration: Connection "tableInfoView" cannot have a prototype object as its destination.

What is this? Am I overlooking something obvious? Or do I need to create a custom cell class and drag the outlet to that? If so, how do I then specify the data which is displayed uniquely for each cell from the UITableViewController?

like image 684
Alex Godbehere Avatar asked Aug 27 '12 22:08

Alex Godbehere


4 Answers

In fact you can't just make an outlet from a dynamic cell prototype in the UITableView delegate view controller.

You'll have to subclass UITableViewCell and then attribute this class to your prototype.

Then you can Ctrl-Drag from the Label to the UITableViewCell subclass header file.

Finaly you can access to this outlet in the delegate code after having imported the UITableViewCell header file in it.

This is documented by Apple there at "The Technique for Dynamic Row Content" section.

like image 132
dulgan Avatar answered Oct 05 '22 05:10

dulgan


or you could give the label a tag (e.g. 100) and use

myLabel = [myTableView viewForTag:100];

to get the label

like image 30
Martin Lockett Avatar answered Oct 05 '22 05:10

Martin Lockett


I had the same error myself. Just to add one more potantial root cause for future readers:

In my case I copied a control (a Button in this case) from one prototype cell to the next and the action still referred to the neighbor cell. My table has several different prototype cells.

The fact, that it acutally was a proper subclass of UITableViewCell which was properly connected to the prototype cell made it difficult to actually see the mistake.

like image 24
Hermann Klecker Avatar answered Oct 05 '22 06:10

Hermann Klecker


Tag the label and you can reach the label anywhere in the viewcontroller like with viewWithTag from the table view.

    UILabel *destinationLabel = (UILabel *)[self.tableView viewWithTag:1];


    destinationLabel.text = @"Label Destaination";
like image 39
Reaper Avatar answered Oct 05 '22 05:10

Reaper