When I first started learning about iPhone development, I would like to share some experiences and experiences on creating simple interfaces, so as not to forget or follow a good record in the future. If there are any deficiencies, please correct them.
This article mainly shares how to create a simple Temperature Converter Using xcode4. Of course, the focus here is not the Temperature Converter, but the method of creating a view. As the first article in this series, a temperature converter will be completed in the simplest way.
Xcode4 has many advantages over xcode3. The most obvious thing is that the Interface builder is not used as an independent application, but is actually built into Xcode4. That is to say, you do not need to switch the view back and forth. If you are not familiar with other things, you can get started with the topic.
1. Create an Xcode Project
Xcode provides us with many templates. Here we use the Navigation-based Application, and then fill in the project name and other options by default. Here I name it HelloWorld.
2. Engineering File Analysis
After the project is created, other HelloWorldAppDelegate is the delegate class. Simply put, the program is delegated to it for execution. the m file contains a series of operations when the program starts or ends.
RootViewController is a control class that controls the operations of views. For example, you can add several buttons in your attempt and then write the corresponding implementation in the control class. Then, you can associate the control class with the interface builder.
3. Open RootViewController. xib and add two labels, two uitextfields and one UIButton control, as shown in
Double-click Label and Button to change the displayed text to the corresponding text in the graph. Select the first UITextFiled, enable Inspector, and change Keyborad to "Numbers and Punctuation" in Attributes Inspector"
Because the second one shows the result, you do not want to accept the input. Select the second UITextField and uncheck Enable CheckOption In the Content in its Attributes Inspector. This is a simple interface.
4. Define two UITextField controls and corresponding buttons in RootViewController. h.
@ Interface RootViewController: UIViewController
{
IBOutlet UITextField * field1;
IBOutlet UITextField * field2;
}
-(IBAction) convert :( id) sender;
5. Implement the convert button in the corresponding. m file
-(IBAction) convert :( id) sender
{
Float invalue = [[field1 text] floatValue];
Float outvalue = (invalue-32.0f) * 5.0f/9.0f;
[Field2 setText: [NSString stringWithFormat: @ "% 3.2f", outvalue];
[Field1 resignFirstResponder]; // hide the opened keyboard
}
This completes the code.
6. The view is designed.The Code is also written, but how to associate the view with the control part? Interface builder provides a convenient method
Click RootViewController. in the xib view, you can see a square like File's Owner. Right-click it and you can see the control you defined and the corresponding converte time, in this case, you can select one of them and drag it to the control in the view to associate the view with the control.
7. Compile and run the program,Such a temperature converter is complete. This article is just a simple explanation, and is not strictly encoded, for example, there is no strict input judgment on the input. This is just a HelloWorld!
In this way, most simple view programs are created by interface builder, so this is a simple method.
The next article will explain how to create an identical program in full encoding mode. If there is anything wrong or something wrong, please correct your discussion.
Original article, reposted from famous sources. Http://blog.csdn.net/everpenny/article/details/6889367