简体   繁体   中英

Why do I need to control-drag some kind of UI-widgets into yellow sphere representing the view controller?

I'm a newbie and am learning the iOS-dev through reading the official tutorial Your First iOS App .

While I don't quite understand the behind meaning of control-dragging the text-filed into the view controller represented by a yellow sphere icon.

I mean it's easy to follow but hard to know the behind reason.

I checked the code after the operation and found nothing is added.

Could someone help to figure out why? TIA.


well, I posted some description the tutorial says to help my question could be understood exactly.

"In the view, Control-drag from the text field to the yellow sphere in the scene dock (the yellow sphere represents the view controller object). When you release the Control-drag, you should see something like this: [sorry image's not allowed to upload for now] . Select delegate in the Outlets section of the translucent panel that appears."

The best way to think about it is, that what you create in Interface Builder has to be linked to your code. A .xib file is really just a complicated XML document. By linking the .xib to the controller it will write code in the XML linking it to the code. otherwise when the .xib and your source code is compiled, the compiler won't link the two entities.

Hope this helps

By control-dragging, we create connections between objects/views in the nib (.xib) file to an action (IBAction) or an outlet (IBOutlet) in View Controller.

Nib files (.xib) has responsibility to establish all connections (actions and outlets). There will be nothing added to your Controller code to reflect the connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM