Write helloworld in IOS xcode 4.2

Source: Internet
Author: User

Xcode 4.2 weakens XIB and uses storyboard. I used XIB to explain the online and purchased tutorials. I wrote a helloworld program.

1. Build a project

Select application under Ios to create an empty application project

(Change project to 4.3 Project (less than 5.0), otherwise an error will be reported during running)

2. Create an XIB File

Right-click the project directory, create a new file, select empty of user interface, and create the mainwindow. XIB file.

3. Open the XIB Interface
Create an object and name it helloappdelegate in the class.
Create a window object, modify the code in appdelegate. H (as follows), and return to the XIB design interface.
@ Property (nonatomic, retain) iboutlet uiwindow * window;
Change the file 'sowner class name to uiapplication (the name must be set; otherwise, the link later may not be connected)

Click Hello app delegate and drag the window on the right to the window in objects.

4. write code
Appdelegate. h

@interface HelloAppDelegate : NSObject <UIApplicationDelegate>{    UIWindow *window;    UILabel *statuText;}@property (nonatomic,retain) IBOutlet UILabel *statuText;@property (nonatomic, retain) IBOutlet UIWindow *window;-(IBAction)buttonClick:(id)sender;@end

Appdelegate. m

@implementation HelloAppDelegate@synthesize window;@synthesize statuText;-(IBAction)buttonClick:(id)sender{    statuText.text = @"Button is pressed";}@end

5. XIB Design

Drag and Drop a label and a button on the interface.

6. Interface and code connection

Select the hello app delegate on the left, and then link the label and statutext, window and windows, as well as the buttonclick event and button in the connection on the right.

7. Click Run.
In the IOS simulator, click the button, and the label word changes.

After completing these operations, I clicked the button in the IOS simulator, but it still didn't respond. After I switched xcode, I opened it and re-run it. The reason is unknown.

Leave a message if you have any questions.


Author's personal website> http://zhoujiajun.com

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.