Swift - Outlets cannot be connected to repeating content

孤街浪徒 提交于 2020-01-02 01:59:20

问题


The full error is: The playerView outlet from the TableViewController to the AVPlayerView is invalid. Outlets cannot be connected to repeating content.

Similar answers like this one have not worked (assuming I am attempting them correctly, I'm very new to iOS).

All I want is a view within a TableViewCell.

I've tried dragging a View in Storyboard to the contentView (and cell) of my TableViewCell, assigning it a class of AVPlayerView: UIView (and a subclass of tableViewCell: AVPlayerView: UITableViewCell), then ctrl+dragging from that view in the storyboard into my TableViewController. Then it doesn't compile. Really confused, thanks for the help.


回答1:


Your table view can have static content or dynamic content.

If you want the table view to have always the same content, set it to static (in interface builder), and then you can link the outlets like that, in the UIViewController.

If you want the table view cells to change dynamically, you cannot do it that way. Because you could repeat cells and the outlet would be ambiguous. You need to create a UITableViewCell subclass for your cells, and create the outlets there.

To clarify: in dynamic table mode, you need to ctrl+drag the outlet into the UITableViewCell subclass, not the view controller.




回答2:


Very simple solution is:

Just take the view or NSLayoutConstraint reference outlets in the subclass of table view cell instead of table view controller and access using object of table view cell in cellForRowAtIndexPath method or any other method.



来源:https://stackoverflow.com/questions/31550519/swift-outlets-cannot-be-connected-to-repeating-content

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