How to get a link to a control in a view?

If I have a UIScrollView configured in the view via Interface Builder, how can I get a link to it in the ViewController implementation? I want to programmatically add labels to the scroll.

For example, in C #, if you have a text field declared in the user interface / form, you can access it simply by using the identifier declared for this text field. It does not seem so simple in the lens c.

Thanks Kevin

+3
source share
2 answers

Assuming I understand you correctly, and you create a view controller from .xib containing subviews, including the UIScrollView that you want, there are two ways: first, you can find it in the subviews array that belongs to the view controller. Secondly, you can add a link to IBOutlet in your header file, and then make a connection using the connection inspector in the interface builder. Then you can refer to the object in your code, change the frame, add tags, etc.

+1
source

You need to connect your ViewController to your Nib files. It is pretty simple. This is your main workflow for using Interface Builder on iPhone / iPad:

  • " " . , " " nib, Command-4 .
  • :

    @property (, ) IBOutlet UIScrollView * scrollView;

IBOutlet - , . , , , Interface Builder , scrollView .

  • , ViewController. , .

- Xcode. - , . !

: , " UIViewController" " ", . nib View Controller, .


  • , , , - , . , Scroll View Interface Builder.
  • ! 'viewDidLoad' , , Nib, , , scrollView ( , Nib , )
+1
source

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


All Articles