Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Outlets from Connections Inspector for Custom View

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?

like image 934
Bhavin Avatar asked Aug 21 '15 14:08

Bhavin


2 Answers

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

like image 192
karthikPrabhu Alagu Avatar answered Nov 09 '22 07:11

karthikPrabhu Alagu


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.

like image 26
Harish Suthar Avatar answered Nov 09 '22 08:11

Harish Suthar