15

I have created a custom view (Quantity View) with nib file in Swift. I have created some IBOutlets & IBActions (for buttons, labels etc.) in my custom view.

I tried to use this custom view (Quantity View) by assigning class name to a UIView in my storyboard. It's showing me all the IBOutlets & IBActions in the Connections Inspector, as shown in this screenshot: screenshot.

I just want to show only delegate for the Custom view.

Possible Answer:

I thought I can use the -viewWithTag to get the views instead of Outlets.

But, I want to know if it's possible with having Outlets also or if there is much better way to do this?

What are the other possible ways (optimum) to handle this situation?

Bhavin
  • 27,155
  • 11
  • 55
  • 94
  • 1
    You have added IBOutlet attributes for your properties and actions. Why don't you want Connections Inspector to show it? IBOutlet is the switch of Connections Inspector. – Harrison Xi Aug 24 '15 at 11:28
  • @HarrisonXi: My custom view is such complex that i don't want to design it through coding only, so i took separate xib to design it, but in order to access the other UI components i need to take `IBOutlet`s in the custom view class, and i also don't want to use `viewWithTag` method. I just want to know if there is any other way. – Bhavin Aug 24 '15 at 12:30
  • No, It's not possible to hide IBOutlets and IBAction Connections Inspector. If you don't want to show in Connections Inspector, Remove IBOutlet keyword from property. – Sonu Aug 31 '15 at 11:45

3 Answers3

2

You can also consider the following solution: You can take the subviews of your QuantityViews(custom view) and you can identify the specific views by its frame origin. Note : you should know the customview subviews frame

karthikPrabhu Alagu
  • 3,371
  • 1
  • 21
  • 25
2

Its not possible to hide IBOutlets from storyboard if you declare the class members as IBs (IBOutlets or IBActions).

The IBOutlets or the IBActions are just indicators to the interface builder so that it can show the names on it when you try to bind them it actually calls the setValue: forKey: method to set the view's reference to the IBOutlet property.

Now if you try to access an subview from the file's owner class without any IBoutlets you need to have a pointer to point it, so for that either you can get the reference using ObjectID which is assigned to the subview by the interface builder or you can get it using the viewWithTag: method.

The ObjectID you need to find all time when you add or replace a subview from the view, so better and convenient approach is to use tag property of UIView class.

So my conclusion to this problem is to access the views using the viewWithTag method you mentioned earlier.

Harish Suthar
  • 711
  • 1
  • 4
  • 14
  • It looks like that UIKit components are not created with Nibs. If it would be a case then we would see few internal @IBOutlets in InterfaceBuilder or they have a tools to hide it. – Blazej SLEBODA Aug 07 '20 at 10:20
-1

I think your way is correct. But sometimes Xcode doesn't work correctly. The following makes the IBOutlets and IBActions reappear and work properly:

  1. Clean project your project in Xcode.

  2. Quit Xcode completely.

  3. Delete all contents of ~/Library/Developer/Xcode/DerivedData/.

  4. Restart MacOS just in case.

I hope you will resolve that :)

pixyzehn
  • 762
  • 6
  • 15