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