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

核能气质少年 提交于 2019-11-28 18:09:37

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.

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

myLabel = [myTableView viewForTag:100];

to get the label

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.

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

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.

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

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.

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