Representatives of UIView & Subview

I just wanted to clarify some of the confusion that I have with a delegate template that needs to be built when there are several UIViews and Subviews of these views. To make it clear, let him define some variables.

Define these objects as:

  • ViewController A
  • Uiview B
  • Subview C

Now I understand how the delegation pattern works (I think), although I'm not sure how to implement this pattern in nested UIViews. Some questions I have:

Should a Cdelegate implemented using superview ( B) be included ?

And if so, should Bpass this information to the ViewController ( A) delegate ?

Here, the script, let it Chave a UITextView, this text display height is determined by the line received from the API service. Bdoes not have access to the API, because this task must be done through ViewController ( A).

If Cthen contains a delegate that points to:

  • Delegate ViewController ( A) implementation ?
  • UIView ( B) delegate implementation ?
  • Other?

If the answer is (2), then should Bthen call ViewController ( A) and pass this information through the event chain?

Here is a little visual:

A <IBDelegate><--- B <ICDelegate><--- CcallsDelegate.OnApiComplete(float height);

What is the "delegate" in this case? ( ICDelegateor IBDelegate). And what is the chain of events?

, UIView, .

, UIViews, , - .

, . .

+4
2

, :

ViewController A → B → C

, ViewController A View B, View C :

  • ViewDelegate View B View C .
  • @property (nonatomic, weak) id <ViewDelegate> delegate; View B.
  • @property (nonatomic, weak) id <ViewDelegate> delegate; View C.
  • ViewController A View B self . viewBObj.delegate = self.
  • View B View C self.delegate . viewBObj.delegate = self.delegate.
  • ViewController A View B View C .
+4

- . , .

, , ( , ). , .

, delegate. , .

B C , . B C, A B.

B , c. B C B (self). ( c, delegate B, , B C).

A B, ( B) A B.

A → B → C.

A

B

B

A (self) B

A , B

B

,

C

C

B (self) C

B , C

C

,

, , iOS.

B C A ( B ).

.

A

B

B

A (self) B

A , B

C

C B

A (self) C

A , C

B

,

C

,

0

Source: https://habr.com/ru/post/1609416/


All Articles