1

I have a UIView with a UIlabel and a UIImage inside it placed on my view controller.

I created a custom class for the UIView and tried to create an IBoutlet for the UIImage and UILabel in the custom class but i will not let me drop it.

I have already clicked on the UIView and set its class to the custom class, so I am not sure why it is not letting me create the outlet.

Below is a screenshot of the custom class, uiview (With image and label). You may have to click on it to see it.

enter image description here

Thanks for your help

Nicholas Muir
  • 2,897
  • 8
  • 39
  • 89
  • I know you say you don't want to add outlets to the `FrontView` itself, but if you did, IB has a long-standing bug that doesn't automatically create outlets to subviews `UIView` subview, but you can do it manually like outlined here: http://stackoverflow.com/a/20295089/1271826 – Rob Aug 14 '16 at 09:56

2 Answers2

3

In your situation, you should connect the outlets to a view controller instead of a view.

Instead of creating a UIView subclass, you should create a UIViewController subclass:

class FrontViewController: UIViewController {

}

Next, select your view controller in the storyboard. In the Identity Inspector (select the tab with an ID card on the panel on the left), type "FrontViewController" (the name of your class) into the "Class" field.

enter image description here

Now you should be able to drag outlets to the class!

Sweeper
  • 213,210
  • 22
  • 193
  • 313
1

As you are crating ViewController there you can connect only view controllers IBOutlets. What you are doing with setting this views class is only marking that this view should behave as this class (you are not creating it there, so you can't set it's IBOutlets). As well this to items won't have anything with tat view, as it's not it creation, that will just be two separate views and YOUR view will be as parent. The only thing you need to understand is that you can create IBOutlet only if it's views creation part, as it's only controllers creation part it's won't give you possibility to create such for his inner view.

Volodymyr
  • 1,165
  • 5
  • 16