In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to write the first iOS11 code Hello,World in iOS11 development, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Code is a collection of command sequences written in computer language to implement a particular function. Now let's use the code to display the "Hello,World" string in the text box. The specific steps are as follows:
(1) use the three view icons of the settings editor, as shown in figure 1.25, to adjust the interface of Xcode to the effect shown in figure 1.26.
Figure 1.25 icons in three views of the editor
Figure 1.26 adjust the interface
(2) hold down the Ctrl key and drag the text box object in the main view, then a blue line will appear and drag the blue line to the ViewController.swift file, as shown in figure 1.27.
Figure 1.27 shows a blue line
(3) when you release the mouse, a dialog box pops up, as shown in figure 1.28.
Figure 1.28 pop-up dialog box
(4) in the pop-up dialog box, find the item Name and enter the name tf, as shown in figure 1.29.
Figure 1.29 enter a name
Note: the name entered in the Name entry is arbitrary.
(5) Select the Connect button, close the dialog box, and automatically generate a line of code in the ViewController.swift file, as shown in figure 1.30.
Figure 1.30 socket variables
Note: the generated code is called the socket variable, which is actually an alias for the associated object. The developer can manipulate the socket variable to manipulate the associated object. The above method is done in conjunction with the socket variable declaration and association, and there is also a way to declare the action first and then the association. The specific steps are as follows:
First, open the ViewController.swift file and declare the socket variable of the text box using the IBOutlet keyword, whose code is shown in figure 1.31.
Figure 1.31 declares socket variables
Note: declared socket variables will appear in a small hollow circle in front of the code. This small circle indicates that the socket variable has not been associated.
Second, use the three view icons of the settings editor to adjust the interface of Xcode to the same effect as figure 1.26.
Then, hold down the Ctrl key and drag the text box object in the main view, and a blue line appears, associating the blue line with the socket variable in the file ViewController.swift file, as shown in figure 1.32.
Figure 1.32 correlating socket variables
Finally, when the mouse is released, the text box object is successfully associated with the socket variable, and the hollow circle in front of the socket variable becomes a solid circle, which indicates that the socket variable has been associated.
(6) Open the ViewController.swift file and write the code. The function of this code is to display the string Hello,World in the text box. The code is as follows:
Import UIKit
Class ViewController: UIViewController {
@ IBOutlet weak var tf: UITextField!
Override func viewDidLoad () {
Super.viewDidLoad ()
/ / Do any additional setup after loading the view, typically from a nib.
Tf.text= "Hello,World" / / set text content
}
Override func didReceiveMemoryWarning () {
Super.didReceiveMemoryWarning ()
/ / Dispose of any resources that can be recreated.
}
}
Note: in order to make it easier for developers to better understand the code, this book will omit the extra code and use "." The ellipsis indicates that the above code becomes the following code:
Import UIKit
Class ViewController: UIViewController {
@ IBOutlet weak var tf: UITextField!
Override func viewDidLoad () {
Super.viewDidLoad ()
/ / Do any additional setup after loading the view, typically from a nib.
Tf.text= "Hello,World" / / set text content
}
……
}
When you run the program at this point, you will see the effect shown in figure 1.33.
Figure 1.33 running effect
These are all the contents of the article "how to write the first iOS11 code Hello,World in iOS11 development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.