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

£可爱£侵袭症+ 提交于 2019-11-27 11:05:21

问题


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?


回答1:


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.




回答2:


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

myLabel = [myTableView viewForTag:100];

to get the label




回答3:


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.




回答4:


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";



回答5:


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.




回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/12150715/strange-error-when-adding-items-to-prototype-cells-in-storyboard-ib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!