ios Swift - 插座无法连接到重复的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31550519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift - Outlets cannot be connected to repeating content
提问by natecraft1
The full error is: The playerView outlet from the TableViewController to the AVPlayerView is invalid. Outlets cannot be connected to repeating content.
完整的错误是:从 TableViewController 到 AVPlayerView 的 playerView 插座无效。插座不能连接到重复的内容。
Similar answers like this onehave not worked (assuming I am attempting them correctly, I'm very new to iOS).
类似的答案,像这样一个没有工作(假设我是正确的尝试他们,我很新于iOS)。
All I want is a view within a TableViewCell.
我想要的只是 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.
我已经尝试将 Storyboard 中的一个视图拖到我的 TableViewCell 的 contentView(和单元格)中,为其分配一个 AVPlayerView 类:UIView(以及 tableViewCell 的一个子类:AVPlayerView:UITableViewCell),然后在故事板中从该视图中按住 ctrl+拖动进入我的 TableViewController。然后它不编译。真的很困惑,谢谢帮助。
回答by Tiago Lira
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
.
如果您希望表格视图始终具有相同的内容,请将其设置为静态(在界面构建器中),然后您可以在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.
如果您希望表格视图单元格动态更改,则不能那样做。因为您可以重复单元格,而出口将是模棱两可的。您需要UITableViewCell
为您的单元格创建一个子类,并在那里创建出口。
To clarify: in dynamic table mode, you need to ctrl+drag the outlet into the UITableViewCell
subclass, not the view controller.
澄清一下:在动态表模式下,您需要按住 ctrl+拖动插座到UITableViewCell
子类中,而不是视图控制器中。
回答by Alok
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.
只需在表格视图单元的子类中获取视图或 NSLayoutConstraint 引用出口,而不是表格视图控制器,并在 cellForRowAtIndexPath 方法或任何其他方法中使用表格视图单元的对象进行访问。