Strange error when adding items to prototype cells

2019-01-21 21:38发布

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?

7条回答
祖国的老花朵
2楼-- · 2019-01-21 22:12

After doing every thing right if problem still exist then just removed all outlets and rejoin them carefully and it worked very fine for me.

查看更多
闹够了就滚
3楼-- · 2019-01-21 22:14

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";
查看更多
太酷不给撩
4楼-- · 2019-01-21 22:16

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.

查看更多
Root(大扎)
5楼-- · 2019-01-21 22:20

Set the right reuse identifier used in .m file in the Storyboard for the Prototype cell.I had the same situation and this helped me

查看更多
姐就是有狂的资本
6楼-- · 2019-01-21 22:25

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.

查看更多
放我归山
7楼-- · 2019-01-21 22:25

I faced the same problem but later it turned out that it was just a silly mistake. I mistakenly dragged the label from Cell to my controller's @interface

This could be your problem too. just cross check once.

查看更多
登录 后发表回答