How to connect IBOutlet from UITableViewController directly to a custom cell?

A few days ago, I watched a video tutorial that explains how to use custom cells in a UITableViewController. I found out that I can prepare a custom cell directly in the interface builder, so I did the following:

I created a UITableViewController and connected a custom class that consists of an IBOutlet (UILabel). After that, I turned on my storyboard and prepared my custom cell using UILabel. Finally, I directly connect the shortcut from the UITableViewController to my custom cell.

The following is done:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x400724860 <IBProxyObject: 0x4007872c0> => productLabel => <IBUIImageView: 0x401080220>> 

Is it impossible to directly connect? In the WWDC 2011 training video (session No. 309), they do exactly what I did. But there is a hook: they do not show the code behind, they just connect it, as I explained above.

For a better understanding, add a screenshot that shows what I'm connecting: enter image description here

+6
source share
2 answers

Actually

I saw the video and they are not connected as you suggest. They connect from cell to UILabel in the cell. In other words, they have a subclass of UITableViewCell and concatenate these IBOutlets in a user object. In your basic form, you can create your own cell class and just declare an interface and synthesize properties, and you should be good to go. Just make sure you set your identifier and custom class in the storyboard correctly.

Hope this helps.

+3
source

I had what turned out to be in the same problem on this issue . As the respondent of my question said, the problem is that the cell here is the prototype of the cell. The relationship between the cell element and the UITableViewController is great for presenting a table with static cells, since they were created at startup, but this does not make sense for cell prototypes, since many of them are likely to be created ... and they do not exist before calling cellForRowAtIndexPath. (This is a very bad error message, and Xcode should probably not allow you to make an illegal connection like this.)

+4
source

Source: https://habr.com/ru/post/900651/


All Articles