IOS growth path-how to associate code with the XIB Interface

Source: Internet
Author: User
Document directory
  • Various problems may occur during the process of adding. At this time, we need to determine what is not written or what is not done:
  • 1. For definition in the class, be sure to add IBOutlet
  • 2. associate with the class
  • 3. Be sure to associate the view

We can use the code writing interface, or design it in a file with the xib extension in the project (selected in the figure)

After opening, there are some common controls in the lower right corner of Xcode

You can drag these controls to the interface:

The following is a simple interface consisting of 7 labels and a Button.

Then write a class file that defines the controls in this interface:

/* ViewController. h */# import <UIKit/UIKit. h> @ interface ViewController: UIViewController {// defines three labels UILabel * titleLabel; UILabel * priceLabel; UILabel * summaryLabel;} @ property (nonatomic, retain) IBOutlet UILabel * titleLabel; @ property (nonatomic, retain) IBOutlet UILabel * priceLabel; @ property (nonatomic, retain) IBOutlet UILabel * summaryLabel;-(IBAction) Edit :( id) sender; @ end

Then, you need to associate the control with the code on the interface to implement the Code design control:

We will see the three icons on the left side of the interface. Select the first icon.

After selection, there is such an area in the upper right corner of Xcode

First, we need to associate this interface with the class to implement it. There is the class at the top of the graph, enter the name of the class to be associated in the box after it (the control attributes are also set)

We have defined three label controls in the class, so we can associate these three with the controls in the interface.

Right-click the first icon on the left side of the interface and the following screen appears:

Note: Only when this interface is associated with the class will the words pricelabel/titlelabel in the figure appear. Of course, if the class is not defined, it will not exist,

Associated operations:

When you add a button Association, the following screen appears. You must select the last-to-last option,

The button is used to implement interface switching.

Remember to associate the view; otherwise, there is no screen program.

Association completed:

Various problems may occur during the process of adding. In this case, determine what is not written or what is not done: 1. to define a class, you must add IBOutlet 2. to be associated with a Class 3. be sure to associate view


Switch between buttons

/* ViewController. m * // implement interface switching-(IBAction) Edit :( id) sender {// The EditViewController * tmpEdit = [[EditViewController alloc] initWithNibName: @ "EditViewController" bundle: nil] interface for converting from this class interface to the EditViewController class; //-(void) presentModalViewController :( UIViewController *) modalViewController animated :( BOOL) animated; // sets the page flip effect tmpEdit. modalTransitionStyle = custom;/* Other page turning effects: UIModalTransitionStyleCoverVertical neural coloring algorithm */[self presentModalViewController: tmpEdit animated: YES]; // implement page switching [tmpEdit autorelease]; NSLog (@ "Edit function called ");}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.