How do I stop the Builder interface that injects a control into a UIView when I drag it?

When I move the controls in Interface Builder and pass in a UIView. In any case, to stop IB from introducing the control into the UIView and make it a child of the UIView in the tree hierarchy.

BEFORE +UIView +UIButton +UIView 

If I move the UIButton with the mouse and place it above the UIView IB, it will become a child of the UIView

 AFTER +UIView +UIButton +UIView 

In any case, block the view from below. I often use them as a background and color them.

+6
source share
2 answers

You can change the position without nesting by pressing and holding Cmd while dragging an item.

Edit: this is only validated for working with Xcode 7.

+3
source

I gave up and decided that all control groups should have a parent UIView. May be invisible (backgroundColor of clearColor)

Select all controls, then choose Editor Menu> Paste In View.

After that, we can safely move them in our own grouping view without their level transitions in the hierarchy.

One of the problems with Embed in View is the use of tags and viewWithTag:

If you are creating your view using multiple VC controllers and tag subtexts, make sure the tag identifiers are unique throughout the view hierarchy.

This is because viewWithTag: returns only the first control that matches the identifier, and appears to perform an ACROSS search in the view hierarchy before moving down to continue the search.

So, if you choose Editor> Paste Into View, you move the control down the hierarchy. So calling viewWithTag: 999 may have picked up your control before that, but it can now return a completely different control.

It may also fall! Its a common way to make a UIView result for a control, such as a UIImageView Then call the control method. If viewWithTag finds a different control than what is expected, it might not even be a UIImageView, so calling the missing method may throw an exception.

BASICALLY never use tags because you need to debug XIB and code and not check for duplicate identifiers. Drag from XIB to .h and create exits.

0
source

All Articles