11

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.

Community
  • 1
  • 1
natecraft1
  • 2,737
  • 9
  • 36
  • 56

2 Answers2

29

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.

Tiago Lira
  • 2,543
  • 1
  • 18
  • 17
  • Hey Tiago, thanks for the reply. I'm not entirely sure I'm doing this right, but I created a class AVPlayerTableViewCell: UITableViewCell, then assigned the cell in the storyboard this class. I also managed to create this outlet @IBOutlet weak var playerView: UIView! within AVPlayerTableViewCell. Now my question is, how do I manage to set properties such as layer on the on the playerView from the TableViewController? – – natecraft1 Jul 22 '15 at 00:13
  • 2
    Sorry for taking so long! That is correct. Now on the controller, you use the tableViewCellForRowAtIndexPath to create and configure the cells. There you can access the player as cell.playerView – Tiago Lira Jul 24 '15 at 03:04
0

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.

Alok
  • 24,880
  • 6
  • 40
  • 67